#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#ifndef ABOBA
#pragma GCC traget("avx2")
#pragma GCC optimize("O3")
#endif

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using uint = unsigned int;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

constexpr ll inf = 1e18, mod = 998244353;

ll binpow(ll a, ll p) {
    if (!p) return 1;
    if (p % 2) return a * binpow(a, p - 1) % mod;
    ll cur = binpow(a, p / 2);
    return cur * cur % mod;
}

int main() {
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto &i: a) cin >> i;
    while (q--) {
        ll b;
        cin >> b;
        if (b == 1) {
            reverse(a.begin(), a.end());
        }
        if (b == 2) {
            for (ll i = 0; i < n; ++i) {
                a[i] = n - a[i] + 1;
            }
        }
        if (b == 3) {
            vector<ll> p(n);
            for (ll i = 0; i < n; ++i) {
                p[a[i] - 1] = i + 1;
            }
            a = p;
        }
        ll ans = 0;
        for (ll i = 0; i < n; ++i) {
            ans = (ans + binpow(a[i], i + 1)) % mod;
        }
        cout << ans << " ";
    }
}

void solve() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll tt = 1;
    //cin >> tt;
    while (tt--) solve();
}
