#include <bits/stdc++.h>
using namespace std;
const int maxx = 1000010;
struct node {
  int num;
  long long val;
  bool operator<(const node &X) const {
    if (val == X.val) return num > X.num;
    return val < X.val;
  }
};
struct nod {
  int num;
  int pos;
  int bj;
} s[maxx];
struct no {
  int l;
  int r;
  int sum;
  long long val;
} tree[maxx];
bool cmp(nod a, nod b) { return a.num < b.num; }
priority_queue<node> q;
long long n, m, k, p;
long long ans = 0, total = 0, sum = 0;
long long a[maxx], b[maxx];
void build(int p, int l, int r) {
  tree[p].l = l, tree[p].r = r;
  int mid = (l + r) >> 1;
  if (l == r) return;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
}
void update(int p, int c, long long val) {
  int l = tree[p].l, r = tree[p].r;
  if (l == r && l == c) {
    tree[p].sum = 1;
    tree[p].val = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (c <= mid)
    update(p << 1, c, val);
  else
    update(p << 1 | 1, c, val);
  tree[p].val = tree[p << 1].val + tree[p << 1 | 1].val;
  tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
}
long long query(int p, int rank) {
  int l = tree[p].l, r = tree[p].r;
  int mid = (l + r) >> 1;
  if (l == r) return tree[p].val;
  if (tree[p << 1].sum >= rank)
    return query(p << 1, rank);
  else
    return query(p << 1 | 1, rank - tree[p << 1].sum);
}
int main() {
  scanf("%lld", &n);
  for (register int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    q.push(node{i, a[i]});
  }
  scanf("%lld", &m);
  for (register int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i].num, &s[i].pos);
    s[i].bj = i;
  }
  sort(s + 1, s + m + 1, cmp);
  build(1, 1, n);
  for (register int i = 1; i <= m; i++) {
    while (total < s[i].num) {
      int u = q.top().num;
      long long val = q.top().val;
      update(1, u, val);
      q.pop();
      total++;
    }
    b[s[i].bj] = query(1, s[i].pos);
  }
  for (register int i = 1; i <= m; i++) printf("%lld\n", b[i]);
  return 0;
}
