#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
int mod = 998244353;
#define o_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
#define int long long
long long bin_pow(long long x, int pow) {
    if (pow == 0)return 1;
    if (pow % 2 == 1)return (x * bin_pow(x, pow - 1)) % mod;
    else {
        return bin_pow((x * x)  % mod, pow / 2) % mod;
    }
}
signed main() {
    int n, q;
    cin >> n >> q;
    vector<int>a(n);
    for (int i = 0;i < n;i++) {
        cin >> a[i];
    }
    int t = 1;
    vector<int>b(n);
    long long ans1 = 0;
    for (int i = 0;i < n;i++) {
        ans1 += bin_pow(a[i],  i + 1);
        ans1 %= mod;
    }
    if (t == 1) {
        for (int i = 0;i < n;i++) {
            b[i] = a[n - i - 1];
        }
    }
    if (t == 2) {

        for (int i = 0;i < n;i++) {
            b[i] = n - a[i] +1 ;
        }
    }
    if (t == 3){

        for (int i = 0;i < n;i++) {
            b[a[i] - 1] = i + 1;
        }
    }
    long long ans = 0;
    swap(a, b);
    for (int i = 0;i < n;i++) {
        ans += bin_pow(a[i],  i + 1);
        ans %= mod;
    }
    /*5 5
1 2 3 4 5
3 1 3 2 2
     */
    int colop = 0;
    for (int i = 0;i < q;i++) {
        int type;
        cin >> type;
        if (type == 3) {
            colop = 0;
            cout << ans1 << " ";
        }else {
            if (colop % 2 == 1)cout << ans1 << " ";
            else {
                cout << ans << " ";
            }
            colop++;
        }
    }
}