#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MOD = 998244353;

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

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n + 1);
    vector<int> p2(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    int types = 3;
    vector<ll> ansprecalc(1 << types);
    for (int mask = 0; mask < (1 << types); mask++) {
        for (int i = 1; i <= n; i++) {
            p2[i] = p[i];
        }
        vector<int> p3(n + 1);
        if (mask & 1) {
            for (int i = 1; i <= n; i++) {
                p3[i] = p2[n - i + 1];
            }
            swap(p2, p3);
        }
        if (mask & (1 << 1)) {
            for (int i = 1; i <= n; i++) {
                p3[i] = n - p2[i] + 1;
            }
            swap(p2, p3);
        }
        if (mask & (1 << 2)){
            for (int i = 1; i <= n; i++) {
                p3[p2[i]] = i;
            }
            swap(p2, p3);
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += binpow(p2[i], i);
            if (ans >= MOD) ans -= MOD;
        }
        ansprecalc[mask] = ans;
    }

    int curmask = 0;
    while (q--) {
        int type;
        cin >> type;
        type--;
        curmask ^= (1 << type);
        cout << ansprecalc[curmask] << " ";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}