#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+7;
const int M = 19;
int h,n,m;
int a[N],dep[N],f[N][M],fa[N][M];
void SiftDown()
{
int x=1;
while((x<<1)<=n)
{
int p;
if(a[x<<1]>a[x<<1|1])p=(x<<1);
else p=(x<<1|1);
if(a[p]==0)break;
x=p;
}
for(int i=0;i<=dep[x];i++)
f[x][i]=a[fa[x][i]];
x=1;
a[1]=0;
while((x<<1)<=n)
{
int p;
if(a[x<<1]>a[x<<1|1])p=(x<<1);
else p=(x<<1|1);
if(a[p]==0)break;
swap(a[x],a[p]);
x=p;
}
}
int col[N],S=0,pw[N];
const int mod = 1e9+7;
int C=0,R=0,E=0,F=0,G=0;
void dfs(int x,int z,int d)
{
if(x>n)return;
if(col[x]==1)
{
if(f[x][d]>z)F=1;
if(f[x][d]==z)G=1;
}
else if(col[x]==2)
{
R--;
if(f[x][d]==z) C++;
if(f[x][d]<z) E++;
}
dfs(x<<1,z,d);dfs(x<<1|1,z,d);
}
int main()
{
cin>>h;n=(1<<h)-1;
pw[0]=1;
for(int i=1;i<=n;i++)pw[i]=1ll*pw[i-1]*2%mod;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=2;i<=n;i++)dep[i]=dep[i>>1]+1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=dep[i>>1];j++)
fa[i][j]=fa[i>>1][j];
fa[i][dep[i]]=i;
}
for(int i=1;i<=n;i++)SiftDown();
cin>>m;
while(m--)
{
int op,x,y;
scanf("%d %d %d",&op,&x,&y);
if(op==1)
{
col[x]=y;
if(col[x]==2)S++;
continue;
}
else if(op==2)
{
if(col[x]==2)S--;
col[x]=0;
continue;
}
C=0;R=S;E=0;F=0;G=0;
dfs(x,y,dep[x]);
int ans=0;
if(F==1)ans=0;
else
{
if(G)ans=pw[C+E];
else ans=1ll*pw[E]*(pw[C]-1+mod)%mod;
}
ans=1ll*ans*pw[R]%mod;
printf("%d\n",ans);
}
return 0;
}