#include <bits/stdc++.h>
using namespace std;
using ll=long long;
map<ll,ll>nx1, nx2,nx3;
map<ll,vector<ll>>mp;
vector<ll>p;
ll n,s,ans, q, i,x,mod=998244353;
ll pow2(ll a, ll b) {
    if (b==0) {
        return 1ll;
    }
    ll s=pow2(a, b/2);
    if (b%2==0) {
        return (s*s)%mod;
    }else {
        return (((s*s)%mod)*a)%mod;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> q;
    for (i=1;i<=n;i++) {
        cin >> x;
        p.push_back(x);
    }
    for (i=0;i<n;i++) {
        s+=pow2(p[i], i+1);
    }
    mp[s]=p;
    while (q--) {
        cin >> x;
        if (x==1) {
            if (nx1.find(s)==nx1.end()) {
                p=mp[s];
                reverse(p.begin(),p.end());
                ans=0;
                for (i=0;i<n;i++) {
                    ans+=pow2(p[i], i+1);
                }
                mp[ans]=p;
                nx1[s]=ans;
            }
            s=nx1[s];
        }else if (x==2) {
            if (nx2.find(s)==nx2.end()) {
                p=mp[s];
                for (i=0;i<n;i++) {
                    p[i]=n-p[i]+1;
                }
                ans=0;
                for (i=0;i<n;i++) {
                    ans+=pow2(p[i], i+1);
                }
                mp[ans]=p;
                nx2[s]=ans;
            }
            s=nx2[s];
        }else {
            if (nx3.find(s)==nx3.end()) {
                p=mp[s];
                vector<ll>q;
                q.resize(n);
                for (i=0;i<n;i++) {
                    q[p[i]-1]=i+1;
                }
                ans=0;
                for (i=0;i<n;i++) {
                    ans+=pow2(q[i], i+1);
                }
                mp[ans]=q;
                nx3[s]=ans;
            }
            s=nx3[s];
        }
        cout << s << ' ';
    }
    return 0;
}