#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, m, w[N], val[N], vat[N];
struct node {
  int a, k;
} f[N];
struct query {
  int t, k, c, s;
} e[N];
inline void add(int u, int l, int r, int t, int xt) {
  if (!vat[t]) vat[t] = xt;
  vat[t] = min(vat[t], xt);
  val[t]++;
  if (l == r) return;
  int d = (l + r) >> 1;
  if (u <= d)
    add(u, l, d, t << 1, xt);
  else
    add(u, d + 1, r, t << 1 | 1, xt);
}
inline int getans(int u, int l, int r, int t, int q) {
  if (l == r) return l;
  int d = (l + r) >> 1;
  if (q + val[t << 1] >= u) return getans(u, l, d, t << 1, q);
  return getans(u, d + 1, r, t << 1 | 1, q + val[t << 1]);
}
inline int getit(int ql, int qr, int l, int r, int t) {
  if (ql == l && qr == r) return vat[t];
  int d = (l + r) >> 1, vas = 1e9 + 7;
  if (ql <= d) vas = min(vas, getit(ql, min(qr, d), l, d, t << 1));
  if (d + 1 <= qr)
    vas = min(vas, getit(max(d + 1, ql), qr, d + 1, r, t << 1 | 1));
  return vas;
}
inline bool cmp(node a, node b) {
  if (a.a == b.a) return a.k < b.k;
  return a.a > b.a;
}
inline bool tmp(query a, query b) { return a.s < b.s; }
inline bool qmp(query a, query b) { return a.c < b.c; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &f[i].a), f[i].k = i, w[i] = f[i].a;
  sort(f + 1, f + n + 1, cmp);
  cin >> m;
  for (int i = 1; i <= m; i++) scanf("%d%d", &e[i].s, &e[i].t), e[i].c = i;
  sort(e + 1, e + m + 1, tmp);
  int c = 1;
  for (int i = 1; i <= m; i++) {
    while (c <= e[i].s) add(f[c].k, 1, n, 1, f[c].a), c++;
    e[i].t = getans(e[i].t, 1, n, 1, 0);
  }
  sort(e + 1, e + m + 1, qmp);
  for (int i = 1; i <= m; i++) printf("%d\n", w[e[i].t]);
}
