#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
using ll = long long;
ll mod = 998244353;

ll Pow(ll x, ll k) {
    ll answ = 1, step = x;
    while (k != 0) {
        if (k & 1) answ *= step;
        step = (step*step)%mod;
        k >>= 1;
    }
    return answ;
}

ll Mul(ll a, ll b) {return (a*b)%mod;}
ll Sum(ll a, ll b) {return (a+b)%mod;}
ll Sub(ll a, ll b) {return (a-b)%mod;}
ll Div(ll a, ll b) {return (a * Pow(b, mod-2))%mod;}

void solve() {
    ll n, q; cin >> n >> q;
    vector<ll> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int _ = 0; _ < q; _++) {
        int type; cin >> type;
        if (type == 1) {
            reverse(p.begin(), p.end());
        } else if (type == 2) {
            for (int i = 0; i < n; i++) p[i] = n - p[i] + 1;
        } else {
            vector<ll> v(n);
            for (int i = 0; i < n; i++) {
                v[p[i]-1] = i+1;
            }
        }
        ll answ = 0;
        for (int i = 0; i < n; i++) {
            answ = Sum(answ, Pow(p[i], i+1));
        }
        cout << answ << " ";
    }
}

int main() {
    cin.tie(0);
    solve();
    return 0;
}