#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 100;
struct leafy {
  int value, size;
  int l, r;
} tree[maxN * 20 + 1];
struct Query {
  int x, pos, id;
} q[maxN + 1];
struct Node {
  int x, p;
} a[maxN + 1];
int n, m, num[maxN + 1];
int res[maxN + 1], cnt, root;
inline int read() {
  int num = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
  return num * f;
}
inline bool cmp1(Node a, Node b) {
  if (a.x == b.x) return a.p < b.p;
  return a.x > b.x;
}
inline bool cmp2(Query a, Query b) { return a.x < b.x; }
inline int new_Node(int value, int size, int l, int r) {
  tree[++cnt] = (leafy){value, size, l, r};
  return cnt;
}
inline void update(int node) {
  if (!tree[node].l) {
    tree[node].size = 1;
    return;
  }
  tree[node].size = tree[tree[node].l].size + tree[tree[node].r].size;
  tree[node].value = tree[tree[node].r].value;
}
inline void rotate(int node) {
  if (tree[tree[node].l].size > tree[tree[node].r].size * 4)
    tree[node].r =
        new_Node(tree[tree[node].r].value,
                 tree[tree[tree[node].l].r].size + tree[tree[node].r].size,
                 tree[tree[node].l].r, tree[node].r),
    tree[node].l = tree[tree[node].l].l;
  if (tree[tree[node].r].size > tree[tree[node].l].size * 4)
    tree[node].l =
        new_Node(tree[tree[tree[node].r].l].value,
                 tree[tree[node].l].size + tree[tree[tree[node].r].l].size,
                 tree[node].l, tree[tree[node].r].l),
    tree[node].r = tree[tree[node].r].r;
  update(node);
}
inline void insert(int node, int x) {
  if (tree[node].size == 1)
    tree[node].l = new_Node(min(tree[node].value, x), 1, 0, 0),
    tree[node].r = new_Node(max(tree[node].value, x), 1, 0, 0);
  else
    insert(x > tree[tree[node].l].value ? tree[node].r : tree[node].l, x);
  update(node);
  rotate(node);
}
inline int find(int node, int x) {
  if (tree[node].size == 1)
    return tree[node].value;
  else
    return x > tree[tree[node].l].size
               ? find(tree[node].r, x - tree[tree[node].l].size)
               : find(tree[node].l, x);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i].x = num[i] = read(), a[i].p = i;
  sort(a + 1, a + n + 1, cmp1);
  m = read();
  for (int i = 1; i <= m; i++) q[i].x = read(), q[i].pos = read(), q[i].id = i;
  sort(q + 1, q + m + 1, cmp2);
  root = new_Node(1e9, 1, 0, 0);
  int now = 1;
  for (int i = 1; i <= m; i++) {
    while (now <= n && now <= q[i].x) insert(root, a[now].p), now++;
    res[q[i].id] = num[find(root, q[i].pos)];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", res[i]);
  return 0;
}
