#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;

const int mod = 998244353;
const int MAXN = 100000 + 13;

int p[MAXN];
int q[MAXN];
int n;
map <vector<int>, int> ansos;

int pw(int x, int y) { // x ** y
    ll ans = 1;
    ll now = x;
    while (y > 0) {
        if (y % 2 == 1) {
            ans *= now;
            ans %= mod;
        }
        y /= 2;
        now *= now;
        now %= mod;
    }
    return ans;
}

int ans() {
    vector <int> vc = {p[1], p[2], p[3], p[4]};
    if (ansos[vc] != 0) {
        return ansos[vc];
    }
    ll ansosk = 0;
    for (int i = 1; i <= n; ++i) {
        ansosk += pw(p[i], i);
        ansosk %= mod;
    }
    ansos[vc] = ansosk;
    return ansosk;
}

void op1() {
    for (int i = 1; i <= n / 2; ++i) {
        swap(p[i], p[n - i + 1]);
    }
}

void op2() {
    for (int i = 1; i <= n; ++i) {
        p[i] = n - p[i] + 1;
    }
}

void op3() {
    for (int i = 1; i <= n; ++i) {
        q[p[i]] = i;
    }
    for (int i = 1; i <= n; ++i) {
        p[i] = q[i];
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int q;
    cin >> q;
    for (int i = 1; i <= n ; ++i) cin >> p[i];
    for (int i = 1; i <= q; ++i) {
        int m;
        cin >> m;
        if (m == 1) {
            op1();
        } else if (m == 2) {
            op2();
        } else {
            op3();
        }
        cout << ans() << " ";
    }
    cout << "\n";
}