#include <bits/stdc++.h>
#define int long long
#define pb piush_back
#define ins insert

using namespace std;

const int mod = 998244353;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, i, j, k, k1, k2, k3, x, x1, x2, x3, t, g;
    cin >> n >> t;
    vector <int> a(n);
    for (auto &it : a)
        cin >> it;
    for (g = 0; g < t; g++) {
        cin >> x;
        if (x == 1)
            reverse(a.begin(), a.end());
        else if (x == 2)
            for (i = 0; i < n; i++)
                a[i] = n - a[i] + 1;
        else {
            vector <int> b;
            b = a;
            for (i = 0; i < n; i++)
                a[b[i] - 1] = i + 1;
        }
        k = 0;
        for (i = 0; i < n; i++) {
            x = int64_t(pow(a[i], i + 1)) % mod;
            k = (k + x) % mod;
        }
        cout << k << ' ';
    }
    return 0;
}
