n = int(input()) A = list(map(int, input().split())) B = [A[0]] + [int(input()) for _ in range(n - 1)] jj = n + 1 for j in range(2, n): if A[j] == A[j - 1]: jj = j break ii = n + 1 for i in range(2, n): if B[i] == B[i - 1]: ii = i break Q = int(input()) for _ in range(Q): t, r, c = map(int, input().split()) if r == 1: print(A[c - 1]) elif c == 1: print(B[r - 1]) elif r + c - 3 > t or A[1] != B[1] or r > ii or c > jj: if t % 2 == 0: print(0) else: print(1) else: print((r + c + A[1] + 1) % 2)