import sys input = sys.stdin.readline T = 20 def naive(N, A, B, qs): X = [[[0] * N for _ in range(N)] for _ in range(T)] for i in range(N): X[0][0][i] = A[i] for i in range(1, N): X[0][i][0] = B[i] # print(*["".join(map(str, row)) for row in X], sep="\n") # print() for t in range(1, T): for i in range(N): for j in range(N): if i == 0 or j == 0: X[t][i][j] = X[t - 1][i][j] else: X[t][i][j] = ( 0 if X[t - 1][i][j] + X[t - 1][i - 1][j] + X[t - 1][i][j - 1] >= 2 else 1 ) # print(*["".join(map(str, row)) for row in X], sep="\n") # print() return [X[t][r][c] for t, r, c in qs] def solve(N, A, B, qs): 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 ans = [] for t, r, c in qs: x = -1 if r == 0: x = A[c] elif c == 0: x = B[r] elif col[r] == -1 or row[c] == -1 or r + c > t + 1: x = t % 2 else: x = A[c] ^ B[r] ^ A[1] ^ 1 ans.append(x) return ans N = int(input()) A = list(map(int, input().split())) B = [A[0]] + [int(input()) for _ in range(N - 1)] Q = int(input()) qs = [] for _ in range(Q): t, r, c = map(int, input().split()) qs.append((t, r - 1, c - 1)) print(*solve(N, A, B, qs), sep="\n")