#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
    for (auto &i : a) {
        is >> i;
    }
    return is;
}

const int mod = 998244353;

int mul(int a, int b) {
    return (a * 1ll * b) % mod;
}

int binpow(int a, int n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 1) {
        return mul(a, binpow(a, n - 1));
    } else {
        int half = binpow(a, n / 2);
        return mul(half, half);
    }
}

int32_t main() {
#ifdef LOCAL
    freopen("C:\\work\\input.txt", "r", stdin);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    cin >> p;
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            reverse(p.begin(), p.end());
        } else if (t == 2) {
            for (int i = 0; i < n; ++i) {
                p[i] = n - p[i] + 1;
            }
        } else {
            vector<int> ind(n);
            for (int i = 0; i < n; ++i) {
                ind[p[i] - 1] = i + 1;
            }
            p = ind;
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            (ans += binpow(p[i], i + 1)) %= mod;
        }
        cout << ans << " ";
    }
    cout << "\n";
    return 0;
}
