#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;

# define len(x) ((ll) x.size())
const ll inf = 1e18;

const ll mod = 998244353;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) { res = res * a % mod; }
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

ll brute(vector<ll>& a) {
    ll cnt = 0;
    for (ll i = 0; i < len(a); ++i) {
        cnt = (cnt + binpow(a[i], i + 1)) % mod;
    }
    return cnt;
}

void solve() {
    ll n, q;
    cin >> n >> q;

    vector<ll> p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> p[i];
    }

    for (ll i = 0; i < q; ++i) {
        ll type;
        cin >> type;

        if (type == 1) {
            reverse(p.begin(), p.end());
        } else if (type == 2) {
            for (ll j = 0; j < len(p); ++j) {
                p[j] = n - p[j] + 1;
            }
        } else {
            vector<ll> oth(n);
            for (ll j = 0; j < n; ++j) {
                oth[p[j] - 1] = j + 1;
            }
            p = oth;
        }

        cout << brute(p) << " ";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();

    return 0;
}