#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 2e5 + 5;
struct node {
  int val, pos;
} s[maxn], ss[maxn];
bool cmp(node a, node b) {
  if (a.val == b.val) return a.pos < b.pos;
  return a.val > b.val;
}
bool cmp1(node a, node b) { return a.pos < b.pos; }
struct question {
  int k, p, idx;
  bool operator<(const question& a) const { return k < a.k; }
} q[maxn];
int ans[maxn];
int c[maxn];
void add(int x, int n) {
  for (int i = x; i <= n; i += i & -i) c[i]++;
}
int sum(int x) {
  int s = 0;
  for (int i = x; i; i -= i & -i) s += c[i];
  return s;
}
int a[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); i++) {
    scanf("%d", &s[i].val);
    a[i] = s[i].val;
    s[i].pos = i;
  }
  sort(s + 1, s + n + 1, cmp);
  int m;
  scanf("%d", &m);
  for (int i = (1); i <= (m); i++) {
    scanf("%d", &q[i].k);
    scanf("%d", &q[i].p);
    q[i].idx = i;
  }
  sort(q + 1, q + m + 1);
  int pp = 1;
  for (int i = (1); i <= (m); i++) {
    while (pp <= q[i].k) {
      add(s[pp].pos, n);
      pp++;
    }
    int l = 1, r = n, gpos;
    while (l <= r) {
      int mid = l + r >> 1;
      if (sum(mid) >= q[i].p)
        r = mid - 1, gpos = mid;
      else
        l = mid + 1;
    }
    ans[q[i].idx] = a[gpos];
  }
  for (int i = (1); i <= (m); i++) printf("%d", ans[i]), puts("");
}
