#include<bits/stdc++.h>

using namespace std;

using ll = long long;

#define f first
#define s second
#define pii pair<int, int>

int const MOD = 998244353;

int sum(int a, int b) {
    if (a + b >= MOD) return a + b - MOD;
    return a + b;
}

ll mult(ll a, ll b) {
    return a * b % MOD;
}

ll bin_pow(ll a, ll p) {
    if (p == 0) return 1;
    if (p == 1) return a;
    int k = bin_pow(a, p / 2);
    return mult(mult(k, k), bin_pow(a, p % 2));
}

ll calc(vector<int> &p) {
    ll res = 0;
//    for (auto el : p) {
//        cout << el << " ";
//    }
//    cout << endl;
    for (int i = 0; i < p.size(); ++i) {
        //cout << i << " " << p[i] << ' ' << bin_pow(p[i], i + 1) << endl;
        res = sum(res, bin_pow(p[i], i + 1));
    }
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    vector<int> p(n), b(q);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < q; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < q; ++i) {
        if (b[i] == 1) {
            reverse(p.begin(), p.end());
        } else if (b[i] == 2) {
            for (int j = 0; j < n; ++j) {
                p[j] = n - p[j] + 1;
            }
        } else {
            vector<int> buf = p;
            for (int j = 0; j < n; ++j) {
                p[buf[j] - 1] = j + 1;
            }
        }
        cout << calc(p) << " ";
    }

}

