#include <bits/stdc++.h>
#include <immintrin.h>

using namespace std;

void solve();

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    cout << fixed << setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

const int mod = 998'244'353;

int add(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}

int sub(int a, int b) {
    return a >= b ? a - b : a + mod - b;
}

int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int bin_pow(int a, int x) {
    int res = 1;
    while (x) {
        if (x & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        x >>= 1;
    }
    return res;
}

int inv(int a) {
    return bin_pow(a, mod - 2);
}

vector<int> inv_perm(const vector<int>& p) {
    vector<int> res(p.size());
    for (int i = 0; i < p.size(); i++) {
        res[p[i]] = i;
    }
    return res;
}

int calc(const vector<int>& p) {
    int res = 0;
    for (int i = 0; i < p.size(); i++) {
        res = add(res, bin_pow(p[i] + 1, i + 1));
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i]; p[i]--;
    }
    int iv = 0, r[2]{};
    int vals[2][2][2]{};
    vals[0][0][0] = calc(p);
    vals[1][0][0] = calc(inv_perm(p));
    for (int i = 0; i < n; i++) {
        p[i] = n - 1 - p[i];
    }
    vals[0][1][0] = calc(p);
    vals[1][1][0] = calc(inv_perm(p));
    for (int i = 0; i < n / 2; i++) {
        swap(p[i], p[n - 1 - i]);
    }
    vals[0][1][1] = calc(p);
    vals[1][1][1] = calc(inv_perm(p));
    for (int i = 0; i < n; i++) {
        p[i] = n - 1 - p[i];
    }
    vals[0][0][1] = calc(p);
    vals[1][0][1] = calc(inv_perm(p));
    while (q--) {
        int type;
        cin >> type;
        if (type == 3) {
            iv ^= 1;
        } else {
            type--;
            type ^= iv;
            r[type] ^= 1;
        }
        cout << vals[iv][r[1]][r[0]] << ' ';
    }
}
