#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const double EPS = 1e-12;
int T, n, m;
int sum[MAXN << 2];
struct A {
  int x, pos;
} a[MAXN], b[MAXN];
struct node {
  int k, pp, id, ans;
} q[MAXN];
inline void Update(int l, int r, int rt, int pos) {
  if (pos == l && l == r) {
    sum[rt] = 1;
    return;
  }
  int mid = (l + r) / 2;
  if (pos <= mid)
    Update(l, mid, rt << 1, pos);
  else
    Update(mid + 1, r, rt << 1 | 1, pos);
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
inline int Query(int l, int r, int rt, int k) {
  if (l == r) return a[l].x;
  int mid = (l + r) / 2;
  if (sum[rt << 1] >= k)
    return Query(l, mid, rt << 1, k);
  else
    return Query(mid + 1, r, rt << 1 | 1, k - sum[rt << 1]);
}
bool cmp1(A aa, A bb) {
  if (aa.x != bb.x)
    return aa.x > bb.x;
  else
    return aa.pos < bb.pos;
}
bool cmp2(node aa, node bb) { return aa.k < bb.k; }
bool cmp3(node aa, node bb) { return aa.id < bb.id; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].x);
    a[i].pos = i;
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1, cmp1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &q[i].k, &q[i].pp);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1, cmp2);
  int now = 0;
  for (int i = 1; i <= m; i++) {
    while (now < q[i].k) Update(1, n, 1, b[++now].pos);
    q[i].ans = Query(1, n, 1, q[i].pp);
  }
  sort(q + 1, q + m + 1, cmp3);
  for (int i = 1; i <= m; i++) printf("%d\n", q[i].ans);
}
