#include<bits/stdc++.h>

using namespace std;

#define int long long

const int eps = 998224353;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<vector<int>> pref(n + 1, vector<int> (n + 1));
    for (int i = 1; i <= n; i++) {
        pref[i][1] = i;
        for (int j = 2; j <= n; j++) {
            pref[i][j] = pref[i][j - 1] * i;
            pref[i][j] %= eps;
        }
    }
    for (int _ = 0; _ < q; _++) {
        int f;
        cin >> f;
        if (f == 1) {
            reverse(p.begin(), p.end());
            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans += pref[p[i]][i + 1];
                ans %= eps;
            }
            cout << ans << endl;
        }
        else if (f == 2) {
            for (int i = 0; i < n; i++) {
                p[i] = n + 1 - p[i];
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans += pref[p[i]][i + 1];
                ans %= eps;
            }
            cout << ans << endl;
        }
        else {
            for (int i = 0; i < n; i++) {
                p[i] = i + 1;
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans += pref[p[i]][i + 1];
                ans %= eps;
            }
            cout << ans << endl;
        }
    }
}

signed main() {
    int t = 1;
    while(t--) {
        solve();
    }
}
