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

using namespace std;

#define ff first
#define ss second
#define rs resize
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

template<typename T, typename T1>
istream& operator >>(istream &in, pair<T, T1> &a) {
    in >> a.ff >> a.ss;
    return in;
}

template<typename T, typename T1>
ostream& operator <<(ostream &out, pair<T, T1> &a) {
    out << a.ff << " " << a.ss;
    return out;
}

template<typename T>
istream& operator >>(istream &in, vector<T> &a) {
    for (auto &i : a) in >> i;
    return in;
}

template<typename T>
ostream& operator <<(ostream &out, vector<T> &a) {
    for (auto i : a) out << i << " ";
    return out;
}

const int maxn = 1e5 + 10, mod = 998244353;

int add(int a, int b) {
    int c = a + b;
    if (c >= mod) c -= mod;
    return c;
}

int mul(int a, int b) {
    int c = a * b;
    if (c >= mod) c %= mod;
    return c;
}

int binpow(int a, int b) {
    if (b == 0) return 1;

    if (b % 2 == 0) {
        int t = binpow(a, b / 2);
        return mul(t, t);
    } else {
        return mul(binpow(a, b - 1), a);
    }
}

int s[maxn];
void solve() {
    int n, q; cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> s[i];

    map<pii, int> d;
    for (int i = -2; i < 3; i++) {
        for (int j = -2; j < 3; j++) {
            int a = 0, b = 0;
            for (auto k = 0; k < n; k++) {
                if (i == 1) a = s[k];
                if (i == -1) a = n - s[k] + 1;
                if (i == 2) a = k + 1;
                if (i == -2) a = n - (k + 1) + 1;

                if (j == 1) b = s[k];
                if (j == -1) b = n - s[k] + 1;
                if (j == 2) b = k + 1;
                if (j == -2) b = n - (k + 1) + 1;

                d[{i, j}] = add(d[{i, j}], binpow(a, b));
            }
        }
    }

    int a = 1, b = 2;
    while (q--) {
        int f; cin >> f;

        if (f == 1) {
            b = -b;
        } else if (f == 2) {
            a = -a;
        } else {
            swap(a, b);
        }

        cout << d[{a, b}] << "\n";
    }
}

int32_t main() {
#ifdef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int test = 1;
    //cin >> test;
    while (test--) {
        solve();
    }
}