#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll

int mod = 998'244'353;

int fp(int x, int a) {
    if (a == 0) {
        return 1;
    }
    int f = fp(x, a / 2);
    if (a & 1) {
        return f * f % mod * x % mod;
    } else {
        return f * f % mod;
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int v = 3;
    int Q = 1 << v;
    vector<int> answ(Q);

    auto rev = [&](vector<int> &b) {
        reverse(b.begin() + 1, b.end());
    };
    auto rot = [&](vector<int> &b) {
        for (int i = 1; i <= n; i++) {
            b[i] = n - b[i] + 1;
        }
    };
    auto obr = [&](vector<int> &b) {
        auto c = b;
        for (int i = 1; i <= n; i++) {
            b[c[i]] = i;
        }
    };
    auto sum = [&](vector<int> &b) {
        int s = 0;
        for (int i = 1; i <= n; i++) {
            (s += fp(b[i], i)) %= mod;
        }
        return s;
    };
    for (int m = 0; m < Q; m++) {
        auto b = a;
        if ((m >> 2) & 1) {
            obr(b);
        }
        if ((m >> 0) & 1) {
            rev(b);
        }
        if ((m >> 1) & 1) {
            rot(b);
        }
        answ[m] = sum(b);
    }
    int cur = 0;
    vector<int> sw = {0, 1, 2, 4};
    for (int i = 0, t; i < q; i++) {
        cin >> t;
        cur ^= sw[t];
        // cout << answ[cur] << " ";
        if (t == 1) {
            rev(a);
        }if (t == 2) {
            rot(a);
        }if (t == 3) {
            obr(a);
        }
        cout << sum(a) << "\n";
    }
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    for (int ts = 1; ts <= t; ts++) {
        solve();
    }
}
