import sys sys.setrecursionlimit((1<<19)-1) #import pypyjit #pypyjit.set_param('max_unroll_recursion=-1') input=sys.stdin.buffer.readline N=int(input()) A=list(map(int,input().split())) A.append(A[-1]) B=[A[0]]+[int(input()) for i in range(N-1)] B.append(B[-1]) col=0 for i in range(1,N): if A[i]==A[i+1]: col=i break row=0 for i in range(1,N): if B[i]==B[i+1]: row=i break if A[1]!=B[1]: row=0 col=0 change=0 if A[1]==B[1]==0: A=[i^1 for i in A] B=[i^1 for i in B] change=1 Q=int(input()) for i in range(Q): T,R,C=map(int,input().split()) R-=1 C-=1 T-=change if R==0: print(A[C]^change) continue if C==0: print(B[R]^change) continue if T<=0: print((T&1)^change) continue if R<=row and C<=col and R+C-1<=T: print(((R+C)&1)^change) continue else: print((T&1)^change) continue