#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll M = 998244353;

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            ll ans = 0;
            reverse(a.begin(), a.end());
            for (int i = 0; i < n; i++) {
                ans += (ll)pow(a[i], i + 1) % M;
                ans %= M;
            }
            cout << ans << ' ';
        } else if (type == 2) {
            ll ans = 0;
            for (int i = 0; i < n; i++) {
                a[i] = n - a[i] + 1;
                ans += (ll)pow(a[i], i + 1) % M;
                ans %= M;
            }
            cout << ans << ' ';
        } else {
            ll ans = 0;
            vector<int> b(n);
            for (int i = 0; i < n; i++) {
                b[a[i] - 1] = i + 1;
            }
            a = b;
            for (int i = 0; i < n; i++) {
                ans += (ll)pow(a[i], i + 1) % M;
                ans %= M;
            }
            cout << ans << ' ';
        }
    }
}
