#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const unsigned long long MOD = 998244353;

unsigned long long binpow(ll a, ll power) {
    if (power == 0) {
        return 1;
    }
    if (power == 1) {
        return a;
    }
    if (power & 1) {
        return binpow(a, power - 1) * a;
    }
    unsigned long long prev = binpow(a, power >> 1);
    return prev * prev;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, q;
    cin >> n >> q;
    vector<ll> p(n);
    for (ll i = 0; i < n; ++i) {
        cin >> p[i];
    }
    while (q--) {
        int op;
        cin >> op;
        unsigned long long sum = 0;
        if (op == 1) {
            vector<ll> t = p;
            reverse(t.begin(), t.end());
            swap(p, t);
            for (int i = 0; i < n; ++i) {
                sum = (sum + (binpow(p[i], i + 1) % MOD) % MOD);
            }
        } else if (op == 2) {
            vector<ll> t(n, 0);
            for (ll i = 0; i < n; ++i) {
                t[i] = n - p[i] + 1;
            }
            swap(p, t);
            for (ll i = 0; i < n;++i) {
                sum = (sum + (binpow(p[i], i + 1) % MOD) % MOD);
            }
        } else {
            vector<ll> t(n, 0);
            for (ll i = 0; i < n; ++i) {
                t[p[i] - 1] = i + 1;
            }
            swap(p, t);
            for (ll i = 0; i < n; ++i) {
                sum = (sum + (binpow(p[i], i + 1) % MOD) % MOD);
            }
        }
        cout << sum % MOD << " ";
    }
    return 0;
}
