#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define int long long

const int mod = 998244353;

int skor(int a, int st) {
    int ans = 1;
    while (st) {
        if (st & 1) {
            ans *= a;
            ans %= mod;
        }
        a *= a;
        a %= mod;
        st >>= 1;
    }
    return ans;
}

int find_sum(vector<int>& a) {
    int ans = 0;
    for (int i = 1; i < sz(a); ++i) {
        ans += skor(a[i], i);
        if (ans >= mod) {
            ans -= mod;
        }
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            reverse(p.begin() + 1, p.end());
        } else if (type == 2) {
            for (int i = 1; i <= n; ++i) {
                p[i] = n - p[i] + 1;
            }
        } else {
            vector<int> g(n + 1);
            for (int i = 1; i <= n; ++i) {
                g[p[i]] = i;
            }
            swap(p, g);
        }
        cout << find_sum(p) << " ";
    }
    return 0;
}