#include <bits/stdc++.h>
#define int long long

using namespace std;

const int mod = 998244353;

int fpow(int a, int pow) {
    if (pow == 0) return 1;
    if (pow % 2 == 1) return a * fpow(a, pow - 1) % mod;
    int hpow = fpow(a, pow / 2);
    return hpow * hpow % mod;
}

int calc(vector<int> p) {
    int n = p.size();
    int res = 0;
    for (int i = 0; i < n; i++) {
        res += fpow(p[i], i + 1);
        res %= mod;
    }
    return res;
}

signed main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    vector<int> ans(8, -1);
    int ops = 0;
    while (q--) {
        int t;
        cin >> t;
        t--;
        ops = ops ^ (1 << t);
        if (ans[ops] != -1 && 0) {
            cout << ans[ops] << " ";
        } else {
            if (t == 0) {
                reverse(a.begin(), a.end());
            } else if (t == 1) {
                for (int& i : a) i = n - i + 1;
            } else {
                vector<int> q(n);
                for (int i = 0; i < n; i++) {
                    q[a[i] - 1] = i + 1;
                }
                a = q;
            }
            ans[ops] = calc(a);
            cout << ans[ops] << " ";
        }
    }
    cout << "\n";
}