#include <bits/stdc++.h>

using namespace std;

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

mt19937 gen(random_device{}());


uniform_real_distribution<ld> dis(0.0, 1e2);

ll binpow(ll x, ll p) {
    if (p == 1) {
        return x;
    }
    if (p % 2 == 1) {
        return binpow(x, p - 1) % 998244353 * x % 998244353;
    }
    ll g = binpow(x, p / 2);
    return g % 998244353 * g % 998244353;
}

vector <ll> p;
ll n;

void rev1() {
    for (ll j = 0; j < n / 2; j++) {
        swap(p[j], p[n - j - 1]);
    }
}

void rev2() {
    for (ll j = 0; j < n; j++) {
        p[j] = n - p[j] + 1;
    }
}

void rev3() {
    vector <ll> q(n);
    for (ll j = 0; j < n; j++) {
        q[p[j] - 1] = j + 1;
    }
    p = q;
}

ll sum() {
    ll x = 0;
    for (ll j = 0; j < n; j++) {
        x = (x + binpow(p[j], j + 1)) % 998244353;
    }
    return x;
}

void solve() {
    ll q;
    cin >> n >> q;
    p.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    if (n <= 1000 and q <= 1000) {
        for (int i = 0; i < q; i++) {
            int x;
            cin >> x;
            if (x == 1) {
                for (int j = 0; j < n / 2; j++) {
                    swap(p[j], p[n - j - 1]);
                }
                ll ans = 0;
                for (int j = 0; j < n; j++) {
                    ans = (ans + binpow(p[j], j + 1))% 998244353;
                }
                cout << ans << " ";
            }
            else if (x == 2) {
                for (int j = 0; j < n; j++) {
                    p[j] = n - p[j] + 1;
                }
                ll ans = 0;
                for (int j = 0; j < n; j++) {
                    ans = (ans + binpow(p[j], j + 1))% 998244353;
                }
                cout << ans << " ";
            }
            else {
                vector <ll> q(n);
                for (int j = 0; j < n; j++) {
                    q[p[j] - 1] = j + 1;
                }
                p = q;
                ll ans = 0;
                for (int j = 0; j < n; j++) {
                    //cout << binpow(p[j], j + 1) << endl;
                    ans = (ans + binpow(p[j], j + 1)) % 998244353;
                }
                cout << ans << " ";
            }
        }
        return;
    }
    ll x1 = 0, x2 = 0, x3 = 0;
    ll ans000 = sum();
    rev1();
    ll ans100 = sum();
    rev2();
    ll ans110 = sum();
    rev3();
    ll ans111 = sum();
    rev1();
    ll ans011 = sum();
    rev2();
    ll ans001 = sum();
    rev1();
    ll ans101 = sum();
    rev1();
    rev3();
    rev2();
    ll ans010 = sum();
    for (ll i = 0; i < q; i++) {
        ll x;
        cin >> x;
        if (x == 1) {
            x1++;
        }
        else if (x == 2) {
            x2++;
        }
        else {
            x3++;
        }
        if (x1 % 2 == 0 and x2 % 2 == 0 and x3 % 2 == 0) {
            cout << ans000 << " ";
        }
        else if (x2 % 2 == 0 and x3 % 2 == 0) {
            cout << ans100 << " ";
        }
        else if (x1 % 2 == 0 and x3 % 2 == 0) {
            cout << ans010 << " ";
        }
        else if (x1 % 2 == 0 and x2 % 2 == 0) {
            cout << ans001 << " ";
        }
        else if (x1 % 2 == 0){
            cout << ans011 << " ";
        }
        else if (x2 % 2 == 0){
            cout << ans101 << " ";
        }
        else if (x3 % 2 == 0){
            cout << ans110 << " ";
        }
        else {
            cout << ans111 << " ";
        }
    }
}


signed main() {
# ifdef  LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    int enter = 1;
    // cin >> enter;
    while (enter--) {
        solve();
    }
}