#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e5 + 10, mod = 9998244353;

int power(int x, int t) {
    if (t == 1) return x;
    if (t % 2 == 1) {
        int k = power(x, t / 2) % mod;
        return (x * k * k) % mod;
    }
    int k = power(x, t / 2) % mod;
    return (k * k) % mod;
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int e = 0; e < q; ++e) {
        int x;
        cin >> x;
        vector<int> b(n);
        if (x == 1) {
            for (int i = 0; i < n; ++i) {
                b[i] = a[n - 1 - i];
            }
        } else if (x == 2) {
            for (int i = 0; i < n; ++i) {
                b[i] = n - a[i] + 1;
            }
        } else {
            for (int i = 0; i < n; ++i) {
                b[a[i] - 1] = i + 1;
            }
        }
        a = b;
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            sum += pow(a[i], i + 1);
            sum %= mod;
        }
        cout << sum << ' ';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int dota = 1;
    //cin >> dota;
    while (dota--) {
        solve();
        cout << '\n';
    }
    return 0;
}
