#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define int ll

const int MOD = 998'244'353;
const int SIGNES = 6;

int bin_up(int x, int p) {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        return (bin_up(x * x, p / 2)) % MOD;
    }
    return (x * bin_up(x, p - 1)) % MOD;
}

int cnt(vector<int> &a) {
    int res = 0;
    for (int i = 0; i < a.size(); i++) {
        res = (res + bin_up(a[i], i + 1)) % MOD;
    }
    return res;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (auto &i : a) {
        cin >> i;
    }
    while (q--) {
        int c;
        cin >> c;
        if (c == 1) {
            reverse(a.begin(), a.end());
        } else if (c == 2) {
            for (int i = 0; i < n; i++) {
                a[i] = n - a[i] + 1;
            }
        } else {
            vector<int> b(n);
            for (int i = 0; i < n; i++) {
                b[a[i] - 1] = i + 1;
            }
            swap(a, b);
        }
        cout << cnt(a) << ' ';
    }
}

signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(SIGNES);

    int q = 1;

    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    cin >> q;
    #endif

    while (q--) {
        solve();
        cout << '\n';
    }

}