//#define _GLIBCXX_DEBUG 1
//#pragma GCC optimize ("03, unroll-seen")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18, mod = 998244353;

ll f(ll zn, ll st) {
    if (st==1)
        return zn;
    if (st%2==0) {
        ll k = f(zn, st/2);
        return k*k%mod;
    }
    if (st%2==1) {
        ll k = f(zn, st-1);
        return k*zn%mod;
    }
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //ifstream cin ("input.txt");
    //ofstream cout ("output.txt");
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    while (m--) {
        ll sum = 0;
        int t;
        cin >> t;
        if (t==1) {
            reverse(a.begin(), a.end());
            for (int i = 0; i < n; i++) {
                sum += f(a[i], i+1);
                sum %= mod;
            }
        } else if (t==2) {
            vector<ll> q(n);
            for (int i = 0; i < n; i++)
                q[i] = n-a[i]+1;
            for (int i = 0; i < n; i++) {
                sum += f(q[i], i+1);
                sum %= mod;
            }
            a = q;
        } else {
            vector<ll> q(n);
            for (int i = 0; i < n; i++) {
                q[a[i]-1] = i+1;
            }
            for (int i = 0; i <n; i++) {
                sum += f(q[i], i+1);
                sum %= mod;
            }
            a = q;
        }
        cout << sum << ' ';
    }
}