#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define cin(x) for (auto &i : (x)) cin >> i;
#define cout(x) for (auto &i : (x)) cout << i << " "; cout << "\n"
#define fori(x) for (int i = 0; i<(x); i++)
#define forj(x) for (int j = 0; j<(x); j++)
#define fork(x) for (int k = 0; k<(x); k++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void apply1(vector<int> &a) {
    int n = a.size();
    fori(n/2) {
        swap(a[i], a[n - i - 1]);
    }
}

void apply2(vector<int> &a) {
    int n = a.size();
    fori(n) {
        a[i] = n - a[i] + 1;
    }
}

void apply3(vector<int> &a) {
    int n = a.size();
    vector<int> b(n);
    fori(n) {
        b[a[i] - 1] = i + 1;
    }
    a = b;
}

const int mod = 998244353;

int mul(int a, int b) {
    return 1ll * a * b % mod;
}

int sum(int a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    return a;
}

int binp(int a, int n) {
    if (n == 0) return 1;
    if (n & 1) return mul(a, binp(a, n - 1));
    int re = binp(a, n / 2);
    return mul(re, re);
}
int calc(vector<int> &a) {
    int n = a.size();
    int re = 0;
    fori(n) {
        re = sum(re,binp(a[i]%mod,i+1));
    }
    return re;
}

void solve() {
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    cin(a);
    fori(q) {
        int t;
        cin >> t;
        if (t==1) apply1(a);
        else if (t==2) apply2(a);
        else apply3(a);
        cout << calc(a) << " ";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}
