#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <numbers>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <bit>
#include <deque>
using namespace std;
using ll = long long;
using db = double;


/* 
void dfs(int v, int p) {
    for (auto u : g[v]) {
        dfs(u, v);
    }
}
*/


/*
int l = 0, r = n + 1;
while (r - l > 1) {
    int mid = (l + r) / 2;
    if (...) {
        l = mid;
    } else {
        r = mid;
    }
}
*/


struct SparseTable {
    vector<vector<ll>> t;

    SparseTable(int n, vector<ll> &a) : t(21, vector<ll>(a.size())) {
        for (int k = 0; k < 21; k++) {
            for (int r = 0; r < n; r++) {
                if (k == 0) {
                    t[k][r] = a[r];
                    continue;
                }

                t[k][r] = max(t[k - 1][r], t[k - 1][r - (1 << (k - 1))]);
            }
        }
    }

    /* ll get(int l, int r) {
        return max(t[][r],
                   t[][r]);
    } */
};


struct Node {
    int val;

    Node() : val(0) {}

    Node(int val) : val(val) {}

    Node merge(const Node &other) const {
        return Node(val + other.val);
    }
};


template <typename Node>
struct Segtree {
    vector<Node> t;
    const Node NE;

    Segtree(int n, const Node &NE) : NE(NE) {
        t.resize(4 * n + 10);
    }

    void build(int v, int l, int r, vector<Node> &a) {
        if (l + 1 == r) {
            t[v] = a[l];
            return;
        }

        int mid = (l + r) / 2;
        build(2 * v + 1, l, mid, a);
        build(2 * v + 2, mid, r, a);
        t[v] = t[2 * v + 1]
        .merge(t[2 * v + 2]);
    }

    Node get(int v, int l, int r, int lq, int rq) {
        if (r <= lq || rq <= l) {
            return NE;
        }

        if (lq <= l && r <= rq) {
            return t[v];
        }

        int mid = (l + r) / 2;
        return get(2 * v + 1, l, mid, lq, rq)
        .merge(get(2 * v + 2, mid, r, lq, rq));
    }

    void update(int v, int l, int r, int i, const Node &x) {
        if (i < l || r <= i) {
            return;
        }

        if (l + 1 == r) {
            t[v] = x;
            return;
        }

        int mid = (l + r) / 2;
        update(2 * v + 1, l, mid, i, x);
        update(2 * v + 2, mid, r, i, x);
        t[v] = t[2 * v + 1]
        .merge(t[2 * v + 2]);
    }
};


vector<ll> rev(vector<ll> a) {
    reverse(a.begin(), a.end());
    return a;
}


vector<ll> res(vector<ll> a) {
    for (int i = 0; i < a.size(); i++) {
        a[i] = a.size() - a[i] + 1;
    }
    return a;
}


vector<ll> inv(vector<ll> a) {
    vector<ll> result(a.size());
    for (int i = 0; i < a.size(); i++) {
        result[a[i] - 1] = i + 1;
    }
    return result;
}


constexpr ll MOD = 998244353;


ll binpow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p % 2 == 0) {
            a *= a;
            a %= MOD;
            p /= 2;
        } else {
            p--;
            res *= a;
            res %= MOD;
        }
    }
    return res;
}


int main() {
    ll n, q, t, i;
    cin >> n >> q;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (auto i : rev(res(inv(rev(res(a)))))) cout << i << ' ';

    vector<ll> answers(50);
    for (int rev_before = 0; rev_before <= 1; rev_before++) {
        auto b = a;
        if (rev_before) b = rev(b); 
        for (int res_before = 0; res_before <= 1; res_before++) {
            auto c = b;
            if (res_before) c = res(b);
            c = inv(c);

            for (int rev_after = 0; rev_after <= 1; rev_after++) {
                auto d = c;
                if (rev_after) d = rev(d);
                for (int res_after = 0; res_after <= 1; res_after++) {
                    auto e = d;
                    if (res_after) e = res(e);

                    int mask = (rev_before) | (res_before << 1) | (rev_after << 2) | (res_after << 3);
                    ll ans = 0;
                    for (int i = 1; i <= n; i++) {
                        ans += binpow(e[i - 1], i);
                        ans %= MOD;
                    }
                    answers[mask] = ans;
                }
            }
        }
    }

    int mask = 0;
    int inve = 0;
    while (q--) {
        cin >> t;
        
        if (t <= 2) {
            t--;
            mask ^= (1 << (t + inve * 2));
        } else {
            if (!inve) {
                inve = true;
            } else {
                int msk2 = mask >> 2;
                int msk1 = mask & 3;
                mask = msk1 ^ msk2;
            }
        }
        cout << answers[mask] << ' ';
        
    }
}
