#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int mod = 1e9+7;

int bin_pow(int a, int n){
    if(n == 1){
        return a;
    }
    if(n%2){
        return ((ll)a*bin_pow(a, n-1))%mod;
    }
    ll x = bin_pow(a, n/2);
    return (x*x)%mod;
}

int calc(vector<int>&p){
    int res = 0;
    for (int i = 0; i<(int)p.size(); i++){
        res+=bin_pow(p[i], i+1);
        res%=mod;
    }
    return res;
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    for (int i = 0; i<n; i++){
        cin >> p[i];
    }
    for (int _ = 0; _<q; _++){
        int b;
        cin >> b;
        if(b == 1){
            reverse(p.begin(), p.end());
        }
        else if(b == 2){
            for (int i = 0; i<n; i++){
                p[i] = n-p[i]+1;
            }
        }
        else{
            vector<int> new_p(n);
            for (int i = 0; i<n; i++){
                new_p[p[i]-1] = i+1;
            }
            p = new_p;
        }
        cout << calc(p) << " ";
    }
}