
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <unordered_map>
using namespace std;
using ll = long long;
using vll = vector<ll>;
ll mod = 998244353;
ll pw(ll n, ll k) {
    ll ans = 1;
    while (k) {
        if (k & 1) ans = ans * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ans;
}
void solve() {
    ll n, q;
    cin >> n >> q;
    vll a(n);
    for (ll& i : a) cin >> i;
    unordered_map<ll, ll> cnt;
    vll ans(8);
    for (ll i = 0; i < 8; ++i) {
        vll b = a;
        if (i & 1) {
            reverse(b.begin(), b.end());
        }
        if (i & 2) {
            for (ll i = 0; i < n; ++i) b[i] = n - b[i] + 1;
        }
        if (i & 4) {
            vll c(n);
            for (ll i = 0; i < n; ++i) c[b[i] - 1] = i + 1;
            b = c;
        }
        ll sum = 0;
        for (ll i = 0; i < n; ++i) sum += pw(b[i], i + 1);
        sum %= mod;
        ans[i] = sum;
    }
    for (ll _ = 0; _ < q; ++_) {
        ll t;
        cin >> t;
        ++cnt[t];
        cnt[t] %= 2;
        if (cnt[1] == 0 && cnt[2] == 0 && cnt[3] == 0) {
            cout << ans[0] << '\n';
        }
        if (cnt[1] == 1 && cnt[2] == 0 && cnt[3] == 0) {
            cout << ans[1] << '\n';
        }
        if (cnt[1] == 0 && cnt[2] == 1 && cnt[3] == 0) {
            cout << ans[2] << '\n';
        }
        if (cnt[1] == 0 && cnt[2] == 0 && cnt[3] == 1) {
            cout << ans[4] << '\n';
        }
        if (cnt[1] == 1 && cnt[2] == 1 && cnt[3] == 0) {
            cout << ans[3] << '\n';
        }
        if (cnt[1] == 1 && cnt[2] == 0 && cnt[3] == 1) {
            cout << ans[5] << '\n';
        }
        if (cnt[1] == 1 && cnt[2] == 1 && cnt[3] == 1) {
            cout << ans[7] << '\n';
        }
        if (cnt[1] == 0 && cnt[2] == 1 && cnt[3] == 1) {
            cout << ans[6] << '\n';
        }
    }
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    cout << endl;
    return 0;
}
