#include <bits/stdc++.h>
using namespace std;
struct node {
  int v, id;
} a[220000];
int v[220000], n, m, k, pos, tree[220000 * 40], ls[220000 * 40],
    rs[220000 * 40], num, root[220000];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' or '9' < c) f = (c == '-' ? -1 : f), c = getchar();
  while ('0' <= c and c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline bool cmp(node x, node y) {
  return x.v > y.v or (x.v == y.v and x.id < y.id);
}
inline void update(int p) { tree[p] = tree[ls[p]] + tree[rs[p]]; }
void build(int &p, int l, int r) {
  p = ++num;
  if (l == r) {
    tree[p] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(ls[p], l, mid);
  build(rs[p], mid + 1, r);
  update(p);
}
void change(int pre, int &p, int l, int r, int x) {
  p = ++num;
  if (l == r) {
    tree[p] = 1;
    return;
  }
  int mid = (l + r) / 2;
  ls[p] = ls[pre];
  rs[p] = rs[pre];
  if (x <= mid)
    change(ls[pre], ls[p], l, mid, x);
  else
    change(rs[pre], rs[p], mid + 1, r, x);
  update(p);
}
int query(int p, int l, int r, int k) {
  if (l == r) return v[l];
  int mid = (l + r) / 2;
  if (k <= tree[ls[p]]) return query(ls[p], l, mid, k);
  k -= tree[ls[p]];
  return query(rs[p], mid + 1, r, k);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &v[i]), a[i].v = v[i], a[i].id = i;
  sort(a + 1, a + n + 1, cmp);
  build(root[0], 1, n);
  for (int i = 1; i <= n; ++i) change(root[i - 1], root[i], 1, n, a[i].id);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &k, &pos);
    printf("%d\n", query(root[k], 1, n, pos));
  }
  return 0;
}
