#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MOD = 998244353, maxn = 1e6;
int a[maxn], c[maxn], b[maxn];
int ans[8];
int per[8][3];

int binpow(int x, int n) {
    if (n == 0) return 1;
    int res = binpow(x, n / 2);
    res = res * res % MOD;
    if (n & 1) res = res * x % MOD;
    return res;
}

int n, q;

mt19937 rnd(55);

int qu[maxn], ans2[maxn], foolans[maxn];

void solve() {
    cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < 8; i++) ans[i] = 0;
    for (int i = 0; i < n; i++) ans[0] = (ans[0] + binpow(a[i], i + 1)) % MOD;
    for (int i = 0; i < n; i++) ans[1] = (ans[1] + binpow(a[i], n - i)) % MOD;
    for (int i = 0; i < n; i++) ans[2] = (ans[2] + binpow(n - a[i] + 1, i + 1)) % MOD;
    for (int i = 0; i < n; i++) ans[3] = (ans[3] + binpow(n - a[i] + 1, n - i)) % MOD;
    for (int i = 0; i < n; i++) ans[4] = (ans[4] + binpow(i + 1, a[i])) % MOD;
    for (int i = 0; i < n; i++) ans[5] = (ans[5] + binpow(i + 1, n - a[i] + 1)) % MOD;
    for (int i = 0; i < n; i++) ans[6] = (ans[6] + binpow(n - i, a[i])) % MOD;
    for (int i = 0; i < n; i++) ans[7] = (ans[7] + binpow(n - i, n - a[i] + 1)) % MOD;
    int cursost = 0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 3; j++) {
            per[i][j] = (i ^ (1 << j));
        }
    }
    per[1][2] = 6;
    per[2][2] = 5;
    per[6][2] = 1;
    per[5][2] = 2;
    for (int i = 0; i < q; i++) {
        int x;
        cin >> x; x--;
        qu[i] = x;
        cursost = per[cursost][qu[i]];
        ans2[i] = ans[cursost];
        cout << ans[cursost] % MOD << " ";
    }
}

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