import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) B = [A[0]] + [int(input()) for _ in range(N - 1)] Q = int(input()) row = [-1] * N row[0] = B[1] for i in range(1, N): if row[i - 1] == A[i]: row[i] = A[i] ^ 1 else: break col = [-1] * N col[0] = A[1] for i in range(1, N): if col[i - 1] == B[i]: col[i] = B[i] ^ 1 else: break for _ in range(Q): T, R, C = map(int, input().split()) R -= 1 C -= 1 ans = -1 if R == 0: ans = A[C] elif C == 0: ans = B[R] elif col[R] == -1 or row[C] == -1: ans = T % 2 else: ans = A[C] ^ B[R] print(ans)