#include<bits/stdc++.h>

using namespace std;

#define int long long

const int eps = 998244353;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> pref(n + 1, vector<int> (30));
    for (int i = 1; i <= n; i++) {
        pref[i][0] = i;
        for (int j = 1; j < 30; j++) {
            pref[i][j] = pref[i][j - 1] * pref[i][j - 1];
            pref[i][j] %= eps;
        }
    }
    string now = "000000000000000000000000000000";
    vector<string> d(n + 1, now);
    for (int i = 1; i <= n; i++) {
        int h = i;
        int u = 0;
        int g = 1;
        while(h > 0) {
            if (h % (2 * g) == g) {
                d[i][u] = '1';
                h -= g;
            }
            g *= 2;
            u += 1;
        }
    }
    vector<int> ans(2);
    int summ = 0;
    for (int i = 1; i <= n; i++) {
        int now1 = 1;
        for (int j = 0; j < 30; j++) {
            if (d[i][j] == '1') {
                now1 *= pref[i][j];
                now1 %= eps;
            }
        }
        summ += now1;
        summ %= eps;
    }
    ans[0] = summ;
    summ = 0;
    for (int i = 1; i <= n; i++) {
        int now1 = 1;
        int h = n - i + 1;
        for (int j = 0; j < 30; j++) {
            // cout << d[i][j] << " ";
            if (d[i][j] == '1') {
                now1 *= pref[h][j];
                now1 %= eps;
            }
        }
        summ += now1;
        summ %= eps;
    }
    // cout << summ << endl;
    ans[1] = summ;
    int y = 0;
    for (int i = 0; i < q; i++) {
        int b;
        cin >> b;
        if (b <= 2) {
            y = (y + 1) % 2;
        }
        cout << ans[y] << endl;
    }
}

signed main() {
    int t = 1;
    while(t--) {
        solve();
    }
}
