#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

int powmod(int v, int mod) {
    int cr = 1;
    while (mod) {
        if (mod & 1) v *= md;
        v *= v;
        cr %= MOD; v %= MOD; mod >>= 1;
    }
    return cr % MOD;
}

int32_t main() {
    int n; cin >> n; int m; cin >> m;
    vector<int> a(n); for (auto &i : a) cin >> i;

    int rs = 0, rsr = 0;
    for (int i = 0; i < n; i++) rs += powmod(i + 1, a[i]);
    for (int i = 0; i < n; i++) rsr += powmod(n - i, a[i]); rs %= MOD; rsr %= MOD;
    int am = 1;
    for (int i = 0; i < m; i++) {
        int v; cin >> v; am += !!(v - 3);
        if (am & 1) cout << rs << ' '; else cout << rsr << ' ';
    }

    return 0;
}