#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;

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

// gp_hash_table<int, int> ht;

const ll MOD = 998244353;

ll binpow(ll a, ll st) {
    if (st == 0) {
        return 1;
    }
    if (st == 1) {
        return a;
    }

    ll temp = binpow(a, st / 2);
    if (st % 2 == 0) {
        return (temp * temp) % MOD;
    }

    return (((temp * temp) % MOD) * a) % MOD;
}

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

    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            reverse(a.begin(), a.end());
        } else if (op == 2) {
            for (int i = 0; i < n; ++i) {
                a[i] = n - a[i] + 1;
            }
        } else {
            vector<int> cur(a);
            for (int i = 0; i < n; ++i) {
                cur[a[i] - 1] = i + 1;
            }
            a = cur;
        }
        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            ans = (ans + binpow(a[i], i + 1)) % MOD;
        }

        cout << ans << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    // if (n * q <= 1e8) {
    //     solve1(n, q);
    //     return 0;
    // }

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<ll> res(8);
    for (int mask = 0; mask < (1 << 3); ++mask) {

        ll ans = 0;
        for (int i = 0; i < n; ++i) {
            int x, y;
            if ((mask >> 0) & 1) {
                x = n - a[i] + 1;
            } else {
                x = a[i];
            }
            if ((mask >> 1) & 1) {
                y = n - i - 1 + 1;
            } else {
                y = i + 1;
            }
            if ((mask >> 2) & 1) {
                swap(x, y);
            }
            // cout << x << ' ' << y << " | ";
            ans = (ans + binpow(x, y)) % MOD;
        }
        // cout << '\n';

        res[mask] = ans;
    }
    

    int mask = 0;
    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            if ((mask >> 2) & 1) {
                mask ^= (1 << 0);
            } else {
                mask ^= (1 << 1);
            }
        } else if (op == 2) {
            if ((mask >> 2) & 1) {
                mask ^= (1 << 1);
            } else {
                mask ^= (1 << 0);
            }
        } else {
            mask ^= (1 << 2);
            // mask ^= (1 << 0);
        }
        cout << res[mask] << ' ';
    }

    return 0;
}
