#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cmath>

#pragma GCC optimize("03")

using namespace std;

//typedef long long ll;
typedef unsigned long long ll;
const ll LINF = 1LL << 62LL;
typedef string str;
#define cin(a) for (auto &el : a) cin >> el;
#define cout(a) { for (auto &el : a) { cout << el; } cout << '\n'; }
#define endl "\n"

const ll MOD = 998244353;

vector<ll> apply(ll b, ll n, vector<ll> v) {
    vector<ll> v_(n);
    for (ll i = 0; i < n; i++) v_[i] = v[i];
    if (b == 1) {
        for (ll i = n-1; i >= 0; i--) v[i] = v_[n-i-1];
    }
    else if (b == 2) {
        for (ll i = 0; i < n; i++) v[i] = n - v_[i] + 1;
    }
    else for (ll i = 0; i < n; i++) v[v_[i] - 1] = i + 1;
    return v;
}

ll cost(ll n, vector<ll> v) {
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ll x = 1;
        for (ll j = 1; j <= i+1; j++) {
            //cout << "_" << x << "_ ";
            x *= v[i];
        }
        ans += x;
        //cout << "+++" << ans << "+++ ";
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll n, q; cin >> n >> q;
    vector<ll> v(n);
    ll ans1 = 0, ans2 = 0;
    for (ll i = 0; i < n; i++) {
        cin >> v[i];
        ans1 += (ll)pow(v[i], i+1);
        ans2 += (ll)pow(v[i], n-i);
    }
    while (q--) {
        ll b; cin >> b;
        // v = apply(b, n, v); cout << cost(n, v) << " "; //cout(v);
        if (b == 3) cout << (ans1 % MOD) << " ";
        else if (b == 2 || b == 1) {
            cout << (ans2 % MOD) << " ";
            swap(ans1, ans2);
        }
    }
    return 0;
}