def solve(): N=int(input()) A=[-1]+list(map(int,input().split())) T=int(input()) F=[0]*(T+1); X=[0]*(T+1); Y=[0]*(T+1) for t in range(1,T+1): F[t],X[t],Y[t]=map(int,input().split()) Question=[[] for _ in range(T+1)] Q=int(input()) for q in range(Q): S,I=map(int,input().split()) Question[S].append((q,I)) G=[[i] for i in range(N+1)] Ans=[0]*Q for t in range(T+1): if F[t]==1: G[X[t]].append(Y[t]) G[Y[t]].append(X[t]) elif F[t]==2: A[X[t]]-=Y[t] elif F[t]==3: for Z in G[X[t]]: A[Z]-=Y[t] elif F[t]==4: stack=[X[t]] seen={X[t]} while stack: Z=stack.pop() A[Z]-=Y[t] for W in G[Z]: if W not in seen: seen.add(W) stack.append(W) for q,I in Question[t]: Ans[q]=max(0, A[I]) return Ans #================================================== import sys input=sys.stdin.readline write=sys.stdout.write write("\n".join(map(str,solve())))