#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mod = 998244353;

ll fast(ll x, ll q) {
    if (q == 0) {
        return 1;
    }
    if (q % 2 == 0) {
        return fast((x * x) % mod, q / 2);
    }
    return (x * fast(x, q - 1)) % mod;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    ll res = 0;
    vector<int> b(q);
    map<pair<int, int>, ll> ans;
    pair<int, int> cur = {0, 0};
    for (int i = 0; i < q; i++) {
        cin >> b[i];
        res = 0;
        if (b[i] == 1) {
            cur.first = 1 - cur.first;
        } else if (b[i] == 2) {
            cur.second = 1 - cur.second;
        }
        if (!ans.count(cur)) {
            vector<ll> a1 = a;
            if (cur.first == 1) {
                for (int j = 0; j < n / 2; j++) {
                    swap(a1[j], a1[n - j - 1]);
                }
            }
            if (cur.second == 1) {
                for (int j = 0; j < n; j++) {
                    a1[j] = n - a1[j] - 1;
                }
            }
            for (int j = 0; j < n; j++) {
                ans[cur] = (ans[cur] + fast(a1[j] + 1, j + 1)) % mod;
            }
        }
        cout << ans[cur] << ' ';
    }
}
