#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
using ll = long long;
#define int ll
const int mod = 998244353;
const int maxn = 1e5 + 10;
int v[maxn];
int cpv[maxn];
int n;
ll bp(ll x, ll p) {
    if (p == 0) {
        return 1;
    }
    if (p % 2== 0) {
        return bp(x * x % mod, p/2);
    }
    return bp(x, p-1) * x % mod;

}
void rev() {
    for (int i = 0; i < n/2; ++i) {
        swap(v[i], v[n - i - 1]);
    }
}
void inv() {
    for (int i = 0; i < n; ++i) {
        v[i] = n + 1 - v[i];
    }
}
void proh() {
    for (int i = 0; i < n; ++i) {
        cpv[i] = v[i];
    }
    for (int i = 0; i < n; ++i) {
        // cout << cpv[i] << " " <<
        v[cpv[cpv[i] - 1] - 1] = cpv[i];
    }
}
ll calc() {
    ll res= 0;

    for (int i = 0; i < n; ++i) {
        res = (res + bp(v[i], i+1))%mod;
    }
    return res;

}
void pr() {
    for (int i = 0; i < n; ++i) {
        cout << v[i] << " ";
    }
    cout << endl;
}
signed main()
{
#ifdef LOCAL
    freopen("main.in", "r", stdin);
    freopen("main.out", "w", stdout);
#endif
    int q;
    cin >> n >> q;
    int a1 = 0;
    int a2 = 0;
    int ans[2][2];
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    ans[0][0] = calc();
    rev();
    ans[1][0] = calc();
    inv();
    ans[1][1] = calc();
    rev();
    ans[1][0] = calc();
    for (int i = 0; i < q; ++i) {
        int b;
        cin >> b;
        if (b == 1) {
            a1 ^= 1;
            // rev();
        }
        if (b == 2) {
            a2 ^= 1;
            // inv();
        }
        if (b == 3) {
            proh();
        }
        // pr();
        cout << ans[a1][a2] << " ";
    }




}