#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const unsigned long long maxn = 1e5+10;
const unsigned long long mod = 998244353;
unsigned long long n,q;
unsigned long long p[maxn],p1[maxn];
unsigned long long ans=0;
void read()
{
    cin>>n>>q;
    for(unsigned long long i=1; i<=n; i++)
    {
        cin>>p[i];
    }
}
unsigned long long pw(unsigned long long base,unsigned long long st)
{
    unsigned long long ans=1;
    while(st>0)
    {
        if(st%2==1)
        {
            ans*=base;
            ans%=mod;
        }
        base*=base;
        base%=mod;
        st/=2;
    }
    return ans;
}
int main()
{
    speed();
    read();
    unsigned long long t;
    for(unsigned long long j=1; j<=q; j++)
    {
        cin>>t;
        ans=0;
        if(t==1)
        {
            reverse(p+1,p+n+1);
            for(unsigned long long i=1; i<=n; i++)
            {
                ans+=pw(p[i],i);
                ans%=mod;
            }
        }
        if(t==2)
        {
            for(unsigned long long i=1; i<=n; i++)
            {
                p[i]=n+1-p[i];
                ans+=pw(p[i],i);
                ans%=mod;
            }
        }
        if(t==3)
        {
            for(unsigned long long i=1; i<=n; i++)
            {
                p1[p[i]]=i;
            }
            for(unsigned long long i=1;i<=n;i++)
            {
                p[i]=p1[i];
            }
            for(unsigned long long i=1; i<=n; i++)
            {
                ans+=pw(p[i],i);
                ans%=mod;
            }
        }
        cout<<ans<<' ';
    }
    return 0;
}
