#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const ll mod = 998244353LL;

ll binpow(ll x, int p) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            res = res * x % mod;
        }
        x = (x * x) % mod;
        p >>= 1;
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector <ll> a(n);
    for (auto &e : a) {
        cin >> e;
    }
    vector ans(2, vector <vector <ll>> (2, vector <ll> (2)));
    for (int b1 = 0; b1 <= 1; b1++) {
        for (int b2 = 0; b2 < 2; b2++) {
            for (int b3 = 0; b3 < 2; b3++) {
                auto p = a;
                if (b1) {
                    reverse(all(p));
                }
                if (b2) {
                    for (auto &e : p) e = n + 1 - e;
                }
                if (b3) {
                    vector <ll> pos(n);
                    for (int i = 0; i < n; i++) {
                        pos[a[i] - 1] = i + 1;
                    }
                }
                for (int i = 0; i < n; i++) {
                    ans[b1][b2][b3] = (ans[b1][b2][b3] + binpow(p[i], i + 1)) % mod;
                }
            }
        }  
    }
    bool b1 = 0, b2 = 0, b3 = 0;
    while (q--) {
        int x;
        cin >> x;
        if (x == 1) {
            b1 ^= 1;
        } else if (x == 2) {
            b2 ^= 1;
        } else {
            b3 ^= 1;
        }
        cout << ans[b1][b2][b3] << ' ';
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}

// Halal code
