
#include <bits/stdc++.h>
#define int int64_t
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;

const int M = 998244353;

int sum(int a, int b) {
    return (a + b) % M;
}

int mul(int a, int b) {
    return a * b % M;
}

int bp(int a, int b) {
    int res = 1;
    while (b)
        if (b & 1)
            res = mul(res, a), b--;
        else
            a = mul(a, a), b /= 2;
    return res;
}

int sm[2][2][2][2][2];


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

    auto sosal = [&](vector<int> &b) {
        for (int &i : b)
            i = n - i + 1;
    };


    for (int i1 = 0; i1 < 2; i1++) {
        for (int i2 = 0; i2 < 2; i2++) {
            for (int i3 = 0; i3 < 2; i3++) {
                for (int i4 = 0; i4 < 2; i4++) {
                    for (int i5 = 0; i5 < 2; i5++) {
                        vector<int> b = a, st(n);
                        iota(all(st), 1);

                        if (i1)
                            sosal(st);
                        if (i2)
                            sosal(b);
                        if (i3)
                            sosal(b);
                        if (i4)
                            sosal(st);

                        if (i1 && i2 && i3 && i5) {
                            cout << ' ';
                        }
                        if (i5)
                            for (int i = 0; i < n; i++)
                                sm[i1][i2][i3][i4][i5] = sum(sm[i1][i2][i3][i4][i5], bp(st[i], b[i]));
                        else
                            for (int i = 0; i < n; i++)
                                sm[i1][i2][i3][i4][i5] = sum(sm[i1][i2][i3][i4][i5], bp(b[i], st[i]));
                    }
                }
            }
        }
    } 


    bool f1 = 0, f2 = 0, f3 = 0;
    bool f4 = 0, f5 = 0;

    while (q--) {
        int x; cin >> x;

        if (x == 1) {
            if (f5)
                f3 ^= 1;
            else
                f1 ^= 1;
        } else if (x == 2) {
            if (f5)
                f4 ^= 1;
            else
                f2 ^= 1;
        } else {
            f5 ^= 1;
        }


        cout << sm[f1][f2][f3][f4][f5] << ' ';
    }
}