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

const int mod = 998244353;

int bp(int x, int p) {
    if (p == 0) return 1;
    if (p & 1) return bp(x, p - 1) * x % mod;
    int res = bp(x, p >> 1);
    return res * res % mod;
}

signed main() {
#ifdef LOCAL
    freopen("test", "r", stdin);
    freopen("res", "w", stdout);
#endif
    int n, q;
    cin >> n >> q;

    vector<int> p(n);
    for (auto &x : p) {
        cin >> x;
    }

    vector<int> p1(n);
    for (int i = 0; i < n; ++i) {
        p1[p[i] - 1] = i + 1;
    }

    int ps = 0, pr = 0, pa = 0, par = 0, p1s = 0, p1r = 0, p1a = 0, p1ar = 0;
    for (int i = 0; i < n; ++i) {
        ps += bp(p[i], i + 1);
        pr += bp(p[i], n - i);
        pa += bp(n - p[i] + 1, i + 1);
        par += bp(n - p[i] + 1, n - i);
        ps %= mod;
        pr %= mod;
        pa %= mod;
        par %= mod;
    }

    for (int i = 0; i < n; ++i) {
        p1s += bp(p1[i], i + 1);
        p1r += bp(p1[i], n - i);
        p1a += bp(n - p1[i] + 1, i + 1);
        p1ar += bp(n - p1[i] + 1, n - i);
        p1s %= mod;
        p1r %= mod;
        p1a %= mod;
        p1ar %= mod;
    }

    bool is1 = false, is2 = false, is3 = false;

    while (q--) {
        int x;
        cin >> x;
        if (x == 3) {
            is3 = !is3;
            swap(is1, is2);
        } else if (x == 2) {
            is2 = !is2;
        } else {
            is1 = !is1;
        }

        if (!is3) {
            if (!is1) {
                if (!is2) cout << ps << '\n';
                else cout << pa << '\n';
            } else {
                if (!is2) cout << pr << '\n';
                else cout << par << '\n';
            }
        } else {
            if (!is1) {
                if (!is2) cout << p1s << '\n';
                else cout << p1a << '\n';
            } else {
                if (!is2) cout << p1r << '\n';
                else cout << p1ar << '\n';
            }
        }
    }
}