#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef long double ld;
#define int long long
#define pii pair<int, int>
#define F first
#define S second

const int mod = 998244353;

vector<int> a;
int n;

int pow(int b, int c) {
    if (c == 0) {
        return 1;
    }
    if (c % 2 == 0) {
        int x = pow(b, c / 2);
        return x * x % mod;
    }
    return pow(b, c - 1) * b % mod;
}

int give() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = (ans + pow(a[i], i + 1)) % mod;
    }
    return ans;
}

void do1() {
    for (int i = 0; i < n / 2; i++) {
        swap(a[i], a[n - 1 - i]);
    }
}

void do2() {
    for (int i = 0; i < n; i++) {
        a[i] = n + 1 - a[i];
    }
}

void do3() {
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        b[a[i] - 1] = i + 1;
    }
    a = b;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int q;
    cin >> n >> q;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ty1 = 0, ty2 = 0, ty3 = 0, pr1 = 0, pr2 = 0;
    int ans[2][2][2];
    for (int k = 0; k < 2; k++) {
        for (int j = 0; j < 2; j++) {
            for (int i = 0; i < 2; i++) {
                ans[i][j][k] = give();
                do1();
            }
            do2();
        }
        do3();
    }
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            ty1 = 1 - ty1;
            pr1 = 1 - pr1;
        } else if (t == 2) {
            ty2 = 1 - ty2;
            pr2 = 1 - pr2;
        } else {
            ty3 = 1 - ty3;
            ty1 = (ty1 - pr1 + pr2 + 10) % 2;
            ty2 = (ty2 - pr2 + pr1 + 10) % 2;
            pr1 = 0;
            pr2 = 0;
        }
        cout << ans[ty1][ty2][ty3] << " ";
    }
    return 0;
} 