#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

#define int long long

int powmod(int v, int mod) {
    int cr = 1;
    while (mod) {
        if (mod & 1) cr *= v;
        v *= v;
        cr %= MOD; v %= MOD; mod >>= 1;
    }
    return cr % MOD;
}

int32_t main() {
    int n; cin >> n; int m; cin >> m;
    vector<int> a(n); for (auto &i : a) cin >> i;

    int rs = 0, rsr = 0;
    for (int i = 0; i < n; i++) rs += powmod(a[i], i + 1);
    for (int i = 0; i < n; i++) rsr += powmod(a[n - i - 1], i + 1); rs %= MOD; rsr %= MOD;
    int am = 1;
    for (int i = 0; i < m; i++) {
        int v; cin >> v;
        if (!(v - 1)) {
            auto p1 = a;
            for (int j = 0; j < n; j++) p1[j] = a[n - 1 - j];
            a = p1;
        } else if (!(v - 2)) {
            auto p1 = a;
            for (int j = 0; j < n; j++) p1[j] = n - a[j] + 1;
            a = p1;
        } else {
            auto p1 = a;
            for (int j = 0; j < n; j++) p1[a[j] - 1] = j + 1; a = p1;
        }
        int r = 0;
        int cur = 0;
        for (auto &j : a) r += powmod(j, ++cur); r %= MOD;
        cout << r << ' ';
    }

    return 0;
}