# include <iostream>
# include <map>
# include <vector>
# include <tuple>
# define int long long
using namespace std;

const long long MOD=998244353,MOD2=1e9+7,MOD3=1e9+9;
const long long K=1e5+11;

long long fpow(long long x, long long k, long long mod)
{
    long long ans=1;
    while(k)
    {
        if(k&1) ans=(ans*x)%mod;
        x=(x*x)%mod;
        k/=2;
    }
    return ans;
}

const int MAX=1e6+11;

int n,q;
int a[MAX];

pair<int,pair<int,int>> calc()
{
    long long ans=0,ans2=0,ans3=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+fpow(a[i],i,MOD))%MOD;
        ans2=(ans2+fpow(K,i,MOD2)*a[i])%MOD2;
        ans3=(ans3+fpow(K,i,MOD3)*a[i])%MOD3;
    }
    return {ans,{ans2,ans3}};
}

void rev()
{
    for(int i=1;i<=n-i+1;i++) swap(a[i],a[n-i+1]);
}

void invert()
{
    for(int i=1;i<=n;i++) a[i]=n-a[i]+1;
}

int b[MAX];
void inverse()
{
    for(int i=1;i<=n;i++) b[a[i]]=i;
    for(int i=1;i<=n;i++) a[i]=b[i];
}

int ct;
map<pair<int,pair<int,int>>,int> mp;
int val[MAX];
vector<int> Data[MAX];
int trans[MAX][4];

void getArr(int id)
{
    for(int i=1;i<=n;i++) a[i]=Data[id][i-1];
}

int getId(pair<int,pair<int,int>> x)
{
    if(mp.find(x)==mp.end())
    {
        ct++;
        mp[x]=ct;
        val[ct]=x.first;
        for(int i=1;i<=n;i++) Data[ct].push_back(a[i]);
    }
    return mp[x];
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];

    pair<int,pair<int,int>> ans=calc();
    int curr=getId(ans);

    for(int i=1;i<=q;i++)
    {
        int type;
        cin>>type;
        if(trans[curr][type]!=0) curr=trans[curr][type];
        else
        {
            getArr(curr);
            if(type==1) rev();
            if(type==2) invert();
            if(type==3) inverse();
            pair<int,pair<int,int>> ans2=calc();
            int id=getId(ans2);
            trans[curr][type]=id;
            curr=id;
        }

        cout<<val[curr]<<" ";
    }
    cout<<"\n";

    return 0;
}

