using ll = long long;
using namespace std;
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
const int M = 998244353;
struct Mint {
    int x;
    Mint(int x = 0) : x(x) {}
    Mint operator+(Mint other) {
        int res = x + other.x;
        if (res >= M)
            res -= M;
        return res;
    }
    Mint operator-(Mint other) {
        int res = x - other.x;
        if (res < 0)
            res += M;
        return res;
    }
    Mint operator*(Mint other) {
        return 1ll * x * other.x % M;
    }
};
Mint binPow(Mint x, int k) {
    if (k == 0)
        return 1;
    if (k & 1)
        return binPow(x, k - 1) * x;
    return binPow(x * x, k / 2);
}
int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ll n, q;
    cin >> n >> q;
    vector <ll> a(n), tmp(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector <Mint> ans(8, 0);
    for (ll mask = 0; mask < 8; ++mask) {
        if (mask & 1) {
            reverse(a.begin(), a.end());
        }
        if (mask & 2) {
            for (ll i = 0; i < n; ++i)
                a[i] = (n - a[i] + 1);
        }
        if (mask & 4) {
            swap(tmp, a);
            for (ll i = 0; i < n; ++i)
                a[tmp[i] - 1] = i + 1;
        }
        for (ll i = 0; i < n; ++i) {
            ans[mask] = ans[mask] + binPow(a[i], i + 1);
        }
        if (mask & 4) {
            swap(tmp, a);
            for (ll i = 0; i < n; ++i)
                a[tmp[i] - 1] = i + 1;
        }
        if (mask & 2) {
            for (ll i = 0; i < n; ++i)
                a[i] = (n - a[i] + 1);
        }
        if (mask & 1) {
            reverse(a.begin(), a.end());
        }
    }
    ll t;
    ll cur = 0;
    while (q--) {
        cin >> t;
        if (t == 3) {
            cur ^= 4;
        } else {
            if (cur & 4) {
                t = 3 - t;
            }
            t--;
            cur ^= (1 << t);
        }
        cout << ans[cur].x << ' ';
    }
}
/*

*/
