
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<ll>;
ll mod = 998244353;
ll pow(ll n, ll k) {
    ll ans = 1;
    while (k) {
        if (k & 1) ans = ans * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ans;
}
void solve() {
    ll n, q;
    cin >> n >> q;
    vll a(n);
    for (ll& i : a) cin >> i;
    for (ll _ = 0; _ < q; ++_) {
        ll t;
        cin >> t;
        if (t == 1) {
            reverse(a.begin(), a.end());
        } else if (t == 2) {
            for (ll i = 0; i < n; ++i) a[i] = n - a[i] + 1;
        } else {
            vll b(n);
            for (ll i = 0; i < n; ++i) b[a[i] - 1] = i + 1;
            swap(a, b);
        }
        ll sum = 0;
        for (ll i = 0; i < n; ++i) sum += pow(a[i], i + 1);
        cout << sum << '\n';
    }
}

int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    cout << endl;
    return 0;
}
