#include <bits/stdc++.h>

using namespace std;
#define int long long
const int mod = 998244353;
int exp(int a, int b) {
    if (b == 0) {
        return 1;
    }
    if (b & 1) {
        return a * exp(a, b - 1) % mod;
    }
    return exp(a * a % mod, b / 2);
}
void bad() {
    int n, q;
    cin >> n >> q;
    vector <int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector <int> cur(n);
    for (int i = 0; i < q; ++i) {
        int b;
        cin >> b;
        --b;
        if (b == 0) {
            reverse(p.begin(), p.end());
        } else if (b == 1) {
            for (int &v : p) {
                v = (n + 1 - v);
            }
        } else {
            for (int i = 0; i < n; ++i) {
                cur[p[i] - 1] = i + 1;
            }
            swap(cur, p);
        }
        int v = 0;
        for (int i = 0; i < n; ++i) {
            v += exp(p[i], i + 1);
            v %= mod;
        }
        cout << v << ' ';
    }
    cout << '\n';
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    bad();
}