#include using namespace std; int nand(int x, int y) {return (x == 1 && y == 1 ? 0 : 1);} int nor(int x, int y) {return (x == 0 && y == 0 ? 1 : 0);} void experiment() { int N; cin >> N; vector A(N), B(N); for(int i = 0; i < N; i++) cin >> A[i]; for(int i = 1; i < N; i++) cin >> B[i]; vector X(N, vector(N)); vector Y(N, vector(N)); for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if(i == 0) X[i][j] = A[j]; if(i != 0 && j == 0) X[i][j] = B[i]; } } for(int t = 1; t < 30; t++) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if(i == 0 || j == 0) Y[i][j] = X[i][j]; if(i != 0 && j != 0 && X[i][j] == 0) Y[i][j] = nand(X[i-1][j], X[i][j-1]); if(i != 0 && j != 0 && X[i][j] == 1) Y[i][j] = nor(X[i-1][j], X[i][j-1]); } } swap(X, Y); cout << "---- " << t << " ----" << endl; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cout << X[i][j] << " "; } cout << endl; } cout << "-----------" << endl; } } int main() { int N; cin >> N; vector A(N), B(N); for(int i = 0; i < N; i++) cin >> A[i]; for(int i = 1; i < N; i++) cin >> B[i]; // コーナーケースの処理 if(N == 1) { int Q; cin >> Q; for(int q = 0; q < Q; q++) { cout << A[0] << endl; } return 0; } // 0101... が最大でいくつ連続するか long long alt_a = 0, alt_b = 0; if(A[1] == B[1]) { alt_a = alt_b = 1; for(int i = 2; i < N; i++) { if(A[i] != A[i-1]) alt_a++; else break; } for(int i = 2; i < N; i++) { if(B[i] != B[i-1]) alt_b++; else break; } } // クエリに答える int Q; cin >> Q; for(int q = 0; q < Q; q++) { int R, C; long long T; cin >> T >> R >> C; R--, C--; if(R == 0) { cout << A[C] << endl; }else if(C == 0) { cout << B[R] << endl; }else if(R <= alt_b && C <= alt_a && R+C-1 <= T) { cout << (R+C-1+A[1])%2 << endl; }else { cout << T%2 << endl; } } }