#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("O3,unroll_loops")
//#pragma GCC target("avx2")

#define int long long
using namespace  std;
using namespace __gnu_pbds;
int const INF = 1e18;

//tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//----------------------------------------------------------------------------------------

int const maxn = 1e6;
int const LG = 23;
int const mod = 998244353;

int binpow(int a, int b) {
    int res = 1;
    while (b != 0) {
        if (b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, qq;
    cin >> n >> qq;


    vector<int> p(n);
    for (auto  &i: p) cin >> i;
    vector<vector<vector<int>>> ans(2, vector<vector<int>> (2, vector<int> (2, 0)));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                vector<int> q = p;
                vector<int> pp = p;
                for (int ind = 0; ind < n; ind++) {
                    if (i) q[ind] = pp[n - ind - 1];
                }
                pp = q;
                for (int ind = 0; ind < n; ind++) {
                    if (j) q[ind] = n - pp[ind] + 1;
                }
                pp = q;
                for (int ind = 0; ind < n; ind++) {
                    if (k) q[pp[ind] - 1] = ind + 1;
                }
                for (int ind = 0; ind < n; ind++) {
                    ans[i][j][k] = (ans[i][j][k] + binpow(q[ind], ind + 1)) % mod;
                }
            }
        }
    }

    int n1 = 0;
    int n2 = 0;
    int n3 = 0;
    while (qq--) {
        int t;
        cin >> t;
        if (t == 1) {
            if (n3) {
                n2 = 1 - n2;
            }
            else {
                n1 = 1 - n1;
            }

        }
        else if (t == 2) {
            if (n3) {
                n1 = 1 - n1;
            }
            else {
                n2 = 1 - n2;
            }

        }
        else n3 = 1 - n3;
        cout << ans[n1][n2][n3] << " ";
    }

    return 0;
}
