#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int MAXN = 1e5 + 10;
const int mod = 998244353;

ll fast_pow(ll x, ll p) {
    if (p == 1)
        return x;

    ll res = fast_pow(x, p / 2);
    if (p % 2 == 0)
        return (res * res) % mod;
    return (((res * res) % mod) * x) % mod;
}

int n, q;
vector<ll> arr, help;

void parse() {
    cin >> n >> q;
    arr.resize(n);
    help.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
}

void ans() {
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += fast_pow(arr[i], i + 1);
        ans %= mod;
    }
    cout << ans << " ";
}

void solve() {
    parse();
    for (int _ = 0; _ < q; ++_) {
        int t; cin >> t;
        if (t == 1)
            reverse(arr.begin(), arr.end());
        else if (t == 2) {
            for (int i = 0; i < n; ++i) {
                arr[i] = n - arr[i] + 1;
            }
        } else {
            for (int i = 0; i < n; ++i) {
                help[arr[i] - 1] = i + 1;
            }
            swap(arr, help);
        }
        ans();
    }
}

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    solve();
}