#include <bits/stdc++.h>

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

#define dbg(x) cerr << #x << " = " << x << endl

const ll LINF = 2e18;
const int INF = 1e9 + 10;
const int LOG = 30;

const int N = 2e5 + 10;
const int MOD = 998244353;
struct modint {
    int val;
    modint(int val_ = 0) : val(val_) {}
    modint(ll val_) : val(val_ % MOD) {}
};
modint operator+(modint a, modint b) {
    int res = a.val + b.val;
    return res >= MOD ? res - MOD : res;
}
modint operator-(modint a, modint b) {
    int res = a.val - b.val;
    return res < 0 ? res + MOD : res;
}
modint operator*(modint a, modint b) {
    return a.val * 1ll * b.val % MOD;
}
void operator+=(modint &a, modint b) {
    int res = a.val + b.val;
    a.val = res >= MOD ? res - MOD : res; 
}
void operator-=(modint &a, modint b) {
    int res = a.val - b.val;
    a.val = res < 0 ? res + MOD : res;
}
void operator*=(modint &a, modint b) {
    a.val = a.val * 1ll * b.val % MOD;
}
modint binpow(modint base, int exp) {
    modint res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}
modint operator~(modint val) {
    return binpow(val, MOD - 2);
}
modint fact[N], invf[N];
void precalc() {
    fact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = fact[i - 1] * i;
    }
    invf[N - 1] = ~fact[N - 1];
    for (int i = N - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1);
    }
}
modint C(int k, int n) {
    if (k > n || n < 0) return 0;
    return fact[n] * invf[k] * invf[n - k];
}


void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int &i : p) cin >> i;

    vector<modint> res(8);
    for (int mask = 0; mask < 8; mask++) {
        vector<int> a = p;
        if (mask & 1) {
            reverse(a.begin(), a.end());
        }
        if ((mask >> 1) & 1) {
            for (int i = 0; i < n; i++) {
                a[i] = n - a[i] + 1;
            }
        }
        if ((mask >> 2) & 1) {
            vector<int> q(n);
            for (int i = 0; i < n; i++) {
                q[a[i] - 1] = i + 1;
            }
            a = q;
        }
        modint ans = 0;
        for (int i = 0; i < n; i++) {
            ans += binpow(a[i], i + 1);
        }
        res[mask] = ans;
    }

    int mask = 0;
    while (q--) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            mask ^= 1;
        } else if (tp == 2) {
            mask ^= 2;
        } else {
            mask ^= 4;
        }
        cout << res[mask].val << " ";
    }
    cout << "\n";
}

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