#include "aplusb.h"
#include <cassert>
#include <cstdio>
// BEGIN SECRET
#include <string>
// END SECRET

int main() {
  // BEGIN SECRET
  const std::string input_secret = "6RzG5ypAE6Nn2UkJEmHczVIji3VjMi4U";
  const std::string output_secret = "G94s1nhbD8VHmHqcW92imRRZhaQgFm9o";
  char secret[1000];
  assert(1 == scanf("%999s", secret));
  if (std::string(secret) != input_secret) {
    printf("%s\n", output_secret.c_str());
    printf("PV\n");
    printf("Possible tampering with the input\n");
    fclose(stdout);
    return 0;
  }
  // END SECRET
  int N;
  assert(1 == scanf("%d", &N));
  std::vector<int> A(N), B(N);
  for (int k = 0; k < N; k++)
    assert(1 == scanf("%d", &A[k]));
  for (int k = 0; k < N; k++)
    assert(1 == scanf("%d", &B[k]));

  int Q;
  assert(1 == scanf("%d", &Q));
  std::vector<int> i(Q), j(Q);
  for (int k = 0; k < Q; k++)
    assert(2 == scanf("%d %d", &i[k], &j[k]));

  fclose(stdin);

  std::vector<int> S(Q);

  initialize(A, B);

  for (int k = 0; k < Q; k++)
    S[k] = answer_question(i[k], j[k]);

  // BEGIN SECRET
  printf("%s\n", output_secret.c_str());
  printf("OK\n");
  // END SECRET
  for (int k = 0; k < Q; k++)
    printf("%d\n", S[k]);

  fclose(stdout);

  return 0;
}
