#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279;
int n, k, i, j, tree[2000005], m, t[200005], ans[200005];
struct str {
  int x, a, id;
} a[200005], q[200005];
bool cmp(str a, str b) {
  if (a.a == b.a) return a.x < b.x;
  return a.a > b.a;
}
bool cmp2(str a, str b) { return a.a < b.a; }
void modify(int i, int l, int r, int x) {
  if (l == r) {
    tree[i] = 1;
    return;
  }
  int mid = l + r >> 1;
  if (mid >= x)
    modify(i << 1, l, mid, x);
  else
    modify(i << 1 | 1, mid + 1, r, x);
  tree[i] = tree[i << 1] + tree[i << 1 | 1];
}
int Query(int i, int l, int r, int y) {
  if (l == r) return t[l];
  int mid = l + r >> 1;
  if (y > tree[i << 1])
    return Query(i << 1 | 1, mid + 1, r, y - tree[i << 1]);
  else
    return Query(i << 1, l, mid, y);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i].a);
    t[i] = a[i].a;
    a[i].x = i;
  }
  sort(a + 1, a + 1 + n, cmp);
  scanf("%d", &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d %d", &q[i].a, &q[i].x);
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m, cmp2);
  int l = 1;
  for (i = 1; i <= m; ++i) {
    for (; l <= q[i].a; ++l) modify(1, 1, n, a[l].x);
    ans[q[i].id] = Query(1, 1, n, q[i].x);
  }
  for (i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
