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

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
 using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5 + 5;
const ll MOD = 998244353;
const ll INF = 3e18;

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n&1) {
            res= res*a % MOD;
        }
        a = a*a%MOD;
        n >>=1;
    }
    return res;

}

vector<ll> fi(vector<ll>&p) {
    ll n = p.size();
    vector<ll> res(p.size());
    for (int i = 0; i <n; ++i) {
        res[i] = p[n-i - 1];
    }
    return res;
}
vector<ll> se(vector<ll>& p) {
    ll n = p.size();
    vector<ll> res(p.size());
    for (int i = 0; i < n; ++i) {
        res[i] = n - p[i] + 1;
    }
    return res;
}
vector<ll> thir(vector<ll>& p) {
    ll n = p.size();
    vector<ll> res(p.size());
    for (int i = 0; i < n; ++i) {
        res[p[i] - 1] = i + 1;
    }
    return res;
}

ll calc (vector<ll>&p) {
    ll n = p.size();
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += binpow(p[i], i + 1);
        ans %= MOD;
    }
    return ans;
}

void solve() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> ans(8);
    vector<vector<ll>> v(8);
    v[0] = a;
    ans[0] = calc(a);
    v[1] = fi(a);
    ans[1] = calc(v[1]);
    v[2] = se(a);
    ans[2] = calc(v[2]);
    v[3] = fi(v[2]);
    ans[3] = calc(v[3]);
    v[4] = thir(a);
    ans[4] = calc(v[4]);
    v[5] = fi(v[4]);
    ans[5] = calc(v[5]);
    v[6] = se(v[4]);
    ans[6] = calc(v[6]);
    v[7] = fi(v[6]);
    ans[7] = calc(v[7]);
    ll cur = 0;
    for (int i = 0; i < q; ++i) {
        ll c;
        cin >> c;
        cur^= (1 << (c-1));
        cout << ans[cur] << " ";
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("C:\\work\\untitled\\in.txt", "r", stdin);
    // freopen("C:\\work\\untitled\\out.txt", "w", stdout);

    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
        cout << '\n';
    }
}