1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<cstdlib>
5 #include<algorithm>
6 #include<cmath>
7 #include<queue>
8 #include<vector>
9 #define inf 0x7fffffff
10 #define lson l,m,rt<<1
11 typedef long long ll;
12 #define rson m+1,r,rt<<1|1
13 using namespace std;
14 const int maxn=1e6+10;
15 struct node{
16 int left,right,maxx,minn;
17 }tree[maxn*4];
18 int st_min[maxn<<2],st_max[maxn<<2];
19 inline int minn(int a,int b){return a>b?b:a;}
20 inline int maxx(int a,int b){return a>b?a:b;}
21 void PushUP(int rt){
22 st_min[rt]=minn(st_min[rt<<1],st_min[rt<<1|1]);
23 st_max[rt]=maxx(st_max[rt<<1],st_max[rt<<1|1]);
24 }
25 void build(int l,int r,int rt) {
26 if(l==r){
27 scanf("%d",&st_min[rt]);
28 st_max[rt]=st_min[rt];
29 return ;
30 }
31 int m=(l+r)>>1;
32 build(lson);
33 build(rson);
34 PushUP(rt);
35 }
36 void update(int p,int num,int l,int r,int rt){
37 if(l==r){
38 st_max[rt]=num;
39 st_min[rt]=num;
40 return ;
41 }
42 int m=(l+r)>>1;
43 if(p<=m)update(p,num,lson);
44 else update(p,num,rson);
45 PushUP(rt);
46 }
47 int query_min(int L,int R,int l,int r,int rt){
48 if (L<=l&&r<=R){
49 return st_min[rt];
50 }
51 int m=(l+r)>>1;
52 int ret1=inf,ret2=inf;
53 if(L<=m)ret1=query_min(L,R,lson);
54 if(R>m) ret2=query_min(L,R,rson);
55 return minn(ret1,ret2);
56 }
57 int query_max(int L,int R,int l,int r,int rt){
58 if(L<=l&&r<=R){
59 return st_max[rt];
60 }
61 int m=(l+r)>>1;
62 int ret1=-inf,ret2=-inf;
63 if(L<=m)ret1=query_max(L,R,lson);
64 if(R>m) ret2=query_max(L,R,rson);
65 return maxx(ret1,ret2);
66 }
67 int main(){
68 int t;
69 scanf("%d",&t);
70 while(t--){
71 int n,m;
72 scanf("%d",&n);
73 int k=pow(2,n);
74 build(1,k,1);
75 scanf("%d",&m);
76 while(m--){
77 int h,a,b;
78 scanf("%d%d%d",&h,&a,&b);
79 if(h==2)update(a+1,b,1,k,1);
80 else{
81 ll ans1=query_min(a+1,b+1,1,k,1);
82 ll ans2=query_max(a+1,b+1,1,k,1);
83 if(ans1<0&&ans2>=0)
84 printf("%lld\n",ans2*ans1);
85 else if(ans1<0&&ans2<0)
86 printf("%lld\n",ans2*ans2);
87 else
88 printf("%lld\n",ans1*ans1);
89 }
90 }
91 }
92 return 0;
93 }