#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, a[200005], ans[200005], pos[200005], sum[800005];
vector<int> qry[200005];
struct ii {
  int x, id;
} b[200005];
bool cmp(ii x, ii y) {
  if (x.x != y.x) return x.x > y.x;
  return x.id < y.id;
}
void update(int x, int l, int r, int y, int c) {
  sum[x] += c;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (y <= mid)
    update(x + x, l, mid, y, c);
  else
    update(x + x + 1, mid + 1, r, y, c);
}
int query(int x, int l, int r, int y) {
  if (l == r) {
    return l;
  }
  int mid = (l + r) / 2;
  if (sum[x + x] >= y) return query(x + x, l, mid, y);
  return query(x + x + 1, mid + 1, r, y - sum[x + x]);
}
int main() {
  scanf("%d", &n);
  for ((i) = 1; (i) <= (n); ++(i)) {
    scanf("%d", &a[i]);
    b[i] = (ii){a[i], i};
  }
  sort(b + 1, b + n + 1, cmp);
  scanf("%d", &m);
  for ((i) = 1; (i) <= (m); ++(i)) {
    int x;
    scanf("%d%d", &x, &pos[i]);
    qry[x].push_back(i);
  }
  for ((i) = 1; (i) <= (n); ++(i)) {
    update(1, 1, n, b[i].id, 1);
    for (__typeof((qry[i]).begin()) it = (qry[i]).begin(); it != (qry[i]).end();
         it++) {
      ans[*it] = a[query(1, 1, n, pos[*it])];
    }
  }
  for ((i) = 1; (i) <= (m); ++(i)) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
