#include <bits/stdc++.h>
using namespace std;
int n, m, ans, tot;
int b[200010], rt[200010];
struct nu {
  int val, id;
} a[200010];
char s[200010];
struct node {
  int ls, rs, sum;
} tree[200010 * 20];
inline bool cmp(const nu &x, const nu &y) {
  if (x.val == y.val)
    return x.id < y.id;
  else
    return x.val > y.val;
}
inline void insert(int num, int &x, int l, int r) {
  tree[++tot] = tree[x];
  x = tot;
  ++tree[x].sum;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (num <= mid)
    insert(num, tree[x].ls, l, mid);
  else
    insert(num, tree[x].rs, mid + 1, r);
}
inline void prework() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i].val), a[i].id = i, b[i] = a[i].val;
  sort(a + 1, a + 1 + n, cmp);
  tot = 0;
  for (int i = 1; i <= n; i++) {
    rt[i] = rt[i - 1];
    insert(a[i].id, rt[i], 1, n);
  }
}
inline int query(int i, int j, int k, int l, int r) {
  if (l == r) return l;
  int tp = tree[tree[j].ls].sum - tree[tree[i].ls].sum;
  int mid = (l + r) >> 1;
  if (k <= tp)
    return query(tree[i].ls, tree[j].ls, k, l, mid);
  else
    return query(tree[i].rs, tree[j].rs, k - tp, mid + 1, r);
}
inline void mainwork() {
  scanf("%d", &m);
  int k, pos;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &k, &pos);
    ans = query(rt[0], rt[k], pos, 1, n);
    printf("%d\n", b[ans]);
  }
}
inline void print() {}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    prework();
    mainwork();
    print();
  }
  return 0;
}
