#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,lzcnt,popcnt,bmi,bmi2")
#define int long long
using namespace std;
long long M =  998244353;


long long binpow(long long x, long long st) {
    if (st == 0) return 1ll;
    else if (st == 1) return x % M;
    int qwe = binpow(x, st / 2);
    if (st % 2 == 0) return (qwe * qwe) % M;
    else return (((qwe * qwe) % M) * x) % M;
}


vector<int> p;


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, q; cin >> n >> q;
    p.assign(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<int> ques(q);
    for (int i = 0; i < q; i++) {cin >> ques[i]; ques[i]--;}
    for (int j = 0; j < q; j++) {
        if (ques[j] == 0) {
            for (int i = 0; i < n / 2; i++) swap(p[i], p[n - i - 1]);
        }
        else if (ques[j] == 1) {
            for (int i  = 0; i < n; i++) p[i] = n - p[i] + 1;
        }
        else {
            vector<int> q(n);
            for (int i = 0; i < n; i++) q[p[i] - 1] = i + 1;
            for (int i = 0; i < n; i++) p[i] = q[i];
        }
        long long ans = 0;
        for (int i = 0; i < n; i++) ans = (ans + binpow(p[i], i + 1)) % M;
        cout << ans << " ";
    }

    return 0;
}