#include <bits/stdc++.h>

using namespace std;
using ll = long long;
vector<ll> v;
const ll mod = 998244353;

ll pw(ll x, ll y) {
    ll ans = 1;
    while (y > 0) {
        ll r = x, k = 1;
        while (k * 2 <= y) {
            r = (r * r) % mod;
            k *= 2;
        }
        y -= k;
        ans = (ans * r) % mod;
    }
    return ans;
}

signed main() {
    ll n, q;
    cin >> n >> q;
    v.resize(n);
    for (ll i = 0; i < n; i++) cin >> v[i];
    while (q--) {
        ll b;
        cin >> b;
        vector<ll> p = v;
        if (b == 1) for (ll i = 0; i < n / 2; i++) swap(v[i], v[n - i - 1]);
        else if (b == 2) for (ll i = 0; i < n; i++) v[i] = n - v[i] + 1;
        else {
            for (ll i = 0; i < n; i++) p[v[i] - 1] = i + 1;
            v = p;
        }
        ll ans = 0;
        for (ll i = 0; i < n; i++) ans = (ans + pw(v[i], i + 1)) % mod;
        cout << ans << ' ';
    }
}
