#include <bits/stdc++.h>
using namespace  std;
#define int long long
const int INF = 1e18;
const int mod = 998244353;
vector <int> give_obr(vector <int> vec) {
    vector <int> ans(vec.size());
    for (int i = 0;i < vec.size();i++) {
        ans[vec[i]] = i;
    }
    return ans;
}
int binpow(int a,int b) {
    if (!b)return 1;
    if (b%2==0) {
        int mid = binpow(a,b/2);
        return (mid * mid) % mod;
    }
    return (a * binpow(a,b-1) )% mod;
}
int give_sum(vector <int> &vec) {
    int n = vec.size();
    int ans = 0;
    for (int i = 0;i < n;i++) {
        ans += binpow(vec[i]+1,i+1);
        if (ans >= mod) {
            ans-=mod;
        }
    }
    return ans;
}
signed main() {
    int n,q;
    cin >> n >> q;
    vector <int> vec(n);
    for (int i =0;i < n;i++) {
        cin >> vec[i];
        vec[i]--;
    }
    int mask = (1<<3);
    vector <int> var_ans(mask);
    for (int i = 0;i < mask;i++) {
        vector <int> tmp = vec;
        if ((i & 1)) {
            for (int i = 0;i < n;i++) {
                tmp[i] = n - vec[i] - 1;
            }
        }
        if ((i >> 1) & 1) {
            vector <int> buf(n);
            for (int i = 0;i < n;i++) {
                buf[i] = tmp[n-i-1];
            }
            tmp = buf;
        }
        if ((i >> 2) & 1) {
            vector <int> buf(n);
            for (int i = 0;i < n;i++) {
                buf[tmp[i]] = i;
            }
            tmp = buf;
        }
        var_ans[i] = give_sum(tmp);
    }
    vector <int> all_zap(q);
    for (int i = 0;i < q;i++) {
        cin >> all_zap[i];
    }
    int mask_now = 0;
    for (auto t : all_zap) {
        if (t==1) {
            mask_now ^= 2;
        }else if (t==2) {
            mask_now ^= 1;
        }else {
            mask_now ^= 4;
        }
        cout << var_ans[mask_now] << " ";
    }
}