#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int A = 1e5 + 5;
const int MOD = 998244353;

ll n, q, i, a[A], tp, b[A];

int binpow(int x, int k) {
    int ans = 1;
    while (k) {
        if (k % 2) ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        k /= 2;
    }
    return ans;
}

int32_t main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    cin >> n >> q;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
    }
    while (q--) {
        cin >> tp;
        if (tp == 1) {
            int ans = 0;
            reverse(a + 1, a + n + 1);
            for (i = 1; i <= n; i++) {
                ans = (ans + binpow(a[i], i)) % MOD;
            }
            cout << ans << " ";
        }
        if (tp == 2) {
            int ans = 0;
            for (i = 1; i <= n; i++) a[i] = n - a[i] + 1;
            for (i = 1; i <= n; i++) {
                ans = (ans + binpow(a[i], i)) % MOD;
            }
            cout << ans << " ";
        }
        if (tp == 3) {
            int ans = 0;
            for (i = 1; i <= n; i++) a[i] = i;
            for (i = 1; i <= n; i++) {
                ans = (ans + binpow(a[i], i)) % MOD;
            }
            cout << ans << " ";
        }

    }
    return 0;
}
