#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18, MOD = 998244353;
mt19937 rnd(time(0));

void solve();

int mt(int a, int b){
    return (a * 1ll * b) % MOD;
}
int sm(int a, int b){
    if (a + b >= MOD){
        return a + b - MOD;
    }
    return a + b;
}
int bin_pow(int a, int n){
    if (n == 0){return 1;}
    if (n == 1){return a;}
    if (n % 2 == 0){return bin_pow(mt(a, a), n / 2);}
    else{
        return mt(a, bin_pow(a, n - 1));
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++){cin >> p[i];}
    while (q--){
        int t;
        cin >> t;
        if (t == 1){
            for (int i = 0; i < n / 2; i++){
                swap(p[i], p[n - i - 1]);
            }
        }
        else if (t == 2){
            for (int i = 0; i < n; i++){
                p[i] = n - p[i] + 1;
            }
        }
        else{
            vector<int> q(n);
            for (int i = 0; i < n; i++){
                q[p[i] - 1] = i + 1;
            }
            p = q;
        }
        int ans = 0;
        for (int i = 0; i < n; i++){
            ans = sm(ans, bin_pow(p[i], i + 1));
        }
        cout << ans << " ";
    }
}


