#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using ll = long long;
using ld = long double;

const int MOD = 998244353;
const int INFi = 1e9;
const ll INF = 1e18;

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int bin_pow(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1) {
            res = res * 1ll * x % MOD;
        }
        y >>= 1;
        x = x * 1ll * x % MOD;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;
    vector<int> a(n), b(q);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < q; i++) {
        cin >> b[i];
    }
    vector<int> ans(8);
    for (int mask = 0; mask < 8; mask++) {
        int flag_rev = (mask >> 1) & 1;
        int flag_rev2 = (mask >> 0) & 1;
        int flag_rev3 = (mask >> 2) & 1;
        auto per = a;
        if (flag_rev) {
            reverse(per.begin(), per.end());
        }
        if (flag_rev2) {
            for (int j = 0; j < n; j++) {
                per[j] = n - per[j] + 1;
            }
        }
        if (flag_rev3) {
            vector<int> per2(n);
            for (int j = 0; j < n; j++) {
                per2[per[j] - 1] = j + 1;
            }
            per = per2;
        }
        for (int j = 0; j < n; j++) {
            ans[mask] = (ans[mask] + bin_pow(per[j], j + 1)) % MOD;
        }
    }
    int flag_rev = 0, flag_rev2 = 0, flag_rev3 = 0;
    for (int i = 0; i < q; i++) {
        if (b[i] == 1) {
            flag_rev ^= 1;
        } else if (b[i] == 2) {
            flag_rev2 ^= 1;
        } else if (b[i] == 3) {
            flag_rev3 ^= 1;
        }
        int mask = flag_rev * 2 + flag_rev2 + flag_rev3 * 4;
        cout << ans[mask] << '\n';
    }
}
