#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ff first
#define ss second

using namespace std;

const int mod = 998244353;

int binpow(int x, int y) {
    if (y == 0) return 1;
    if (y % 2 == 0) return binpow((x * x) % mod, y / 2);
    else return (x * binpow(x, y - 1)) % mod;
}

int sum(int a, int b) {
    if (a + b >= mod) return a + b - mod;
    return a + b;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    vector <int> req(q);
    for (int i = 0; i < q; ++i) {
        cin >> req[i];
    }
    int ans00 = 0, ans10 = 0, ans11 = 0, ans01 = 0;
    for (int i = 1; i <= n; ++i) {
        ans00 = sum(ans00, binpow(a[i], i));
        ans10 = sum(ans10, binpow(a[n - i + 1], i));
        ans11 = sum(ans11, binpow(n - a[n - i + 1] + 1, i));
        ans01 = sum(ans01, binpow(n - a[i] + 1, i));
    }
    bool f1 = false, f2 = false;
    for (int i = 0; i < q; ++i) {
        if (req[i] == 3) swap(f1, f2);
        else if (req[i] == 1) f1 ^= 1;
        else f2 ^= 1;
        if (!f1 && !f2) cout << ans00 << ' ';
        else if (f1 && !f2) cout << ans10 << ' ';
        else if (f1 && f2) cout << ans11 << ' ';
        else cout << ans01 << ' ';
    }
    return;

}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int t = 1;
    while (t--) solve(), cout << '\n';
}