#pragma GCC optimize("O3, unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define int long long

const int mod =998244353;

int binpow(int a, int n) {
    if (n == 0) return 1LL;
    if (n % 2 == 0) {
        int c = binpow(a, n / 2);
        return c * c % mod;
    }
    return a * binpow(a, n - 1) % mod;
}


vector<int> op1(vector<int> a) {
    int n = (int) a.size();
    for (int i = 0; i < n / 2; i++) {
        swap(a[i], a[n - i - 1]);
    }
    return a;
}

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

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

vector<int> upd(vector<int> a) {
    vector<int> st;
    for (int x : a) {
        if (!st.empty() && st.back() == x) {
            st.pop_back();
        } else {
            st.push_back(x);
        }
    }
    return st;
}

int get(vector<int> a) {
    int ans = 0;
    int n = (int) a.size();
    for (int i = 0; i < n; i++) {
        ans = (ans + binpow(a[i], i + 1)) % mod;
    }
    return ans;
}

mt19937 rng(time(0));

int ans[4][2][4];
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
            for (int h = 0; h < 4; h++) {
                vector<int> nw = p;
                if (i == 1) {
                    nw = op1(nw);
                } else if (i == 2) {
                    nw = op2(nw);
                } else if (i == 3) {
                    nw = op1(op2(nw));
                }
                if (j) {
                    nw = op3(nw);
                }
                if (h == 1) {
                    nw = op1(nw);
                } else if (h == 2) {
                    nw = op2(nw);
                } else if (h == 3) {
                    nw = op1(op2(nw));
                }

                ans[i][j][h] = get(nw);
                /*cout << get(nw) << "\n";
                cout << i << " " << j << " " << h << "\n";
                cout << "\n";*/
            }
        }
    }
    int sm0, sm1, sm2;
    sm0 = sm1 = sm2 = 0;
    while (q--) {
        int c; cin >> c;
        if (c == 1) {
            if (sm1 > 0) {
                if (sm2 == 0) {
                    sm2 = 1;
                } else if (sm2 == 1) {
                    sm2 = 0;
                } else if (sm2 == 2) {
                    sm2 = 3;
                } else if (sm2 == 3) {
                    sm2 = 2;
                }
            } else {
                if (sm0 == 0) {
                    sm0 = 1;
                } else if (sm0 == 1) {
                    sm0 = 0;
                } else if (sm0 == 2) {
                    sm0 = 3;
                } else if (sm0 == 3) {
                    sm0 = 2;
                }
            }
        } else if (c == 2) {
            if (sm1 > 0) {
                if (sm2 == 1) {
                    sm2 = 3;
                } else if (sm2 == 2) {
                    sm2 = 0;
                } else if (sm2 == 3) {
                    sm2 = 1;
                } else {
                    sm2 = 2;
                }
            } else {
                if (sm0 == 1) {
                    sm0 = 3;
                } else if (sm0 == 2) {
                    sm0 = 0;
                } else if (sm0 == 3) {
                    sm0 = 1;
                } else {
                    sm0 = 2;
                }
            }
        } else {
            if (sm1) {
                if (sm2 == 0) {
                    sm2 = 0;
                } else if (sm2 == 1) {
                    sm2 = 2;
                } else if (sm2 == 2) {
                    sm2 = 1;
                } else if (sm2 == 0) {
                    sm2 = 0;
                } else {
                    sm2 = 3;
                }
                if (sm0 == sm2) {
                    sm0 = 0;
                } else if (sm0 == 0 || sm2 == 0) {
                    sm0 = max(sm0, sm2);
                } else {
                    sm0 = 3;
                }
                sm2 = 0;
            }
            sm1 ^= 1;
        }
        //cout << sm0 << " " << sm1 << " " << sm2 << '\n';
        cout << ans[sm0][sm1][sm2] << "\n";
    }

}