#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int n;
ll bp(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

ll cnt(vector<ll> a) {
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + bp(a[i], i)) % mod;
    }
    return ans;
}

void solve() {
    int q;
    cin >> n >> q;
    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    //if (n <= 1000 && q <= 1000) {
        while (q--) {
            int tp;
            cin >> tp;
            ll ans = 0;
            vector<ll> b(n + 1);
            for (int i = 1; i <= n; i++) {
                if (tp == 1) {
                    b[i] = a[n - i + 1];
                }
                else if (tp == 2) {
                    b[i] = (n - a[i] + 1);
                }
                else {
                    b[a[i]] = i;
                }
            }
            cout << cnt(b) << " ";
            a = b;
        }
        return;
    //}
}

int main() {
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}