#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;

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 5e5 + 11;
const int mod = 998244353;
#define int long long
int bpow (int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) (res *= a) %= mod;
        (a *= a) %= mod;
        n >>= 1;
    }
    return res;
}
signed main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int n, q;
    cin >> n >> q;
    vector<int> p(n + 1);
    for (int i = 1; i <= n; ++i) cin >> p[i];
    int t1 = 0, t2 = 0, t3 = 0;
    int ans[2][2][2];
    vector<int> S = p;
    for (int p1 = 0; p1 < 2; ++p1) {
        for (int p2 = 0; p2 < 2; ++p2) {
            for (int p3 = 0; p3 < 2; ++p3) {
                ans[p1][p2][p3] = 0;
                for (int i = 1; i <= n; ++i) {
                    int val = p[i], pos = i;
                    if (p1) pos = n - pos + 1;
                    if (p2) val = n - val + 1;
                    if (p3) swap (pos, val);
                    (ans[p1][p2][p3] += bpow (val, pos)) %= mod;
                }
            }
        }
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            if (!t3) t1 ^= 1;
            else t2 ^= 1;
            cout << ans[t1][t2][t3] << ' ';
        } else if (t == 2) {
            if (!t3) t2 ^= 1;
            else t1 ^= 1;
            cout << ans[t1][t2][t3] << ' ';
        } else {
            t3 ^= 1;
            cout << ans[t1][t2][t3] << ' ';
        }
    }

}

