#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma optimize("O3")

using namespace std;

using ll = long long;

const int INF = 1e9 + 7, mod = 998244353;

#ifdef LOCAL
const int MAXN = 1e2;
#else
const int MAXN = 1e6;
#endif

int n;
vector<int> p;

ll bp(ll a, ll b) {
    if (b == 0)
        return 1;
    if (b % 2)
        return (a * bp(a, b - 1)) % mod;
    ll res = bp(a, b / 2);
    return (res * res) % mod;
}

void a1() {
    reverse(p.begin(), p.end());
}

void a2() {
    vector<int> now(n);
    for (int i = 0; i < n; i++) {
        now[i] = n - p[i] - 1;
    }
    p = now;
}

void a3() {
    vector<int> now(n);
    for (int i = 0; i < n; i++)
        now[p[i]] = i;
    p = now;
}

void print() {
    for (int i : p)
        cout << i << ' ';
    cout << '\n';
}

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

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q;
    cin >> n >> q;
    p.resize(n);
    for (int &i : p) {
        cin >> i;
        i--;
    }
    while(q--){
        int type;
        cin >> type;
        if(type == 1) a1();
        else if(type == 2) a2();
        else a3();
        cout << clc() << ' ';
    }
    return 0;
}
