#pragma GCC optimize("O3,unroll-loops")
#include <string>
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>

using namespace std;

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

const ll mod = 998244353;

ll fpow (ll a, ll n) {
    ll ans = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            ans = (ans * a) % mod;
            --n;
        }
        a = (a * a) % mod;
        n /= 2;
    }
    return ans;
}

void Solve () {
    int n, q;
    cin >> n >> q;
    vector<ll>a(n);
    for (ll& i : a) {
        cin >> i;
    }
    ll ans[8];
    for (int i = 0; i < 8; ++i) {
        ans[i] = 0;
        vector<ll>now = a;
        if (i & 1) {
            reverse(now.begin(), now.end());
        }
        if ((i & 2) >> 1) {
            for (int j = 0; j < n; ++j) {
                now[j] = n - now[j] + 1;
            }
        }
        if ((i & 4) >> 2) {
            vector<ll>now1(n);
            for (int j = 0; j < n; ++j) {
                now1[now[j] - 1] = j + 1;
            }
            now = now1;
        }
        for (int j = 0; j < n; ++j) {
            ans[i] += fpow(now[j], j + 1);
            ans[i] %= mod;
        }
    }
    int now = 0;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        now ^= (1 << (t - 1));
        cout << ans[now] << ' ';
    }
}

signed main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        Solve();
    }
}