#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef __int128 lll;

const ll inf=1e18+1,mod=998244353;
const ld eps=1e-9,pi=acos(-1);
#define all(a) a.begin(), a.end()
#define mpp make_pair
#define F first
#define S second

mt19937_64 rng(234);

ll binpow(ll n,ll k) {
    if (!k)
        return 1;
    if (k%2)
        return (binpow(n,k-1)*n)%mod;
    ll a=binpow(n,k/2);
    return (a*a)%mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,qr;cin>>n>>qr;
    vector<int>p(n);
    for (auto &i:p)
        cin>>i;
    ll t1=0,t2=0,t3=0;
    while (qr--) {
        ll t;cin>>t;
        auto q=p;
        if (t==1)
            reverse(all(q));
        if (t==2)
            for (auto &i:q)
                i=n+1-i;
        if (t==3) {
            auto q2=q;
            for (ll i=0;i<n;i++)
                q2[q[i]-1]=i+1;
            q=q2;
        }
        ll sm=0;
        for (ll i=0;i<n;i++)
            sm=(sm+binpow(q[i],i+1))%mod;
        cout<<sm<<' ';
        p=q;
    }
}