#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 ans[2][2][2];
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                ans[i][j][k] = 0;
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        ans[0][0][0] = sum(ans[0][0][0], binpow(a[i], i));
        ans[1][0][0] = sum(ans[1][0][0], binpow(a[n - i + 1], i));
        ans[1][1][0] = sum(ans[1][1][0], binpow(n - a[n - i + 1] + 1, i));
        ans[0][1][0] = sum(ans[0][1][0], binpow(n - a[i] + 1, i));
        
        ans[0][0][1] = sum(ans[0][0][1], binpow(i, a[i]));
        ans[1][0][1] = sum(ans[1][0][1], binpow(i, a[n - i + 1]));
        ans[1][1][1] = sum(ans[1][1][1], binpow(i, n - a[n - i + 1] + 1));
        ans[0][1][1] = sum(ans[0][1][1], binpow(i, n - a[i] + 1));
    }
    int f1 = 0, f2 = 0, f3 = 0;
    for (int i = 0; i < q; ++i) {
        if (req[i] == 3) f3 ^= 1, swap(f1, f2);
        else if (req[i] == 1) f1 ^= 1;
        else f2 ^= 1;
        cout << ans[f1][f2][f3] << ' ';
    }
    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';
}