#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
int valu[200010];
struct qry {
  int k, pos, ind, ans;
} q[200010];
struct Node {
  int val, ind;
  bool operator<(const Node& rhs) const {
    if (val == rhs.val) return ind < rhs.ind;
    return val > rhs.val;
  }
} a[200010];
int c[200010];
int getsum(int x) {
  int ans = 0;
  while (x) {
    ans += c[x];
    x -= x & (-x);
  }
  return ans;
}
void update(int x, int v) {
  while (x <= n) {
    c[x] += v;
    x += x & (-x);
  }
}
bool cmp1(const qry& a, const qry& b) { return a.k < b.k; }
bool cmp2(const qry& a, const qry& b) { return a.ind < b.ind; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].val);
    valu[i] = a[i].val;
    a[i].ind = i;
  }
  sort(a + 1, a + n + 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    q[i].ind = i;
    scanf("%d%d", &q[i].k, &q[i].pos);
  }
  sort(q + 1, q + m + 1, cmp1);
  int beg = 1;
  for (int i = 1; i <= n; i++) {
    update(a[i].ind, 1);
    while (q[beg].k == i) {
      int l = 1, r = n, mid;
      while (l < r) {
        mid = (l + r) >> 1;
        if (getsum(mid) < q[beg].pos)
          l = mid + 1;
        else
          r = mid;
      }
      q[beg].ans = valu[l];
      beg++;
    }
  }
  sort(q + 1, q + m + 1, cmp2);
  for (int i = 1; i <= m; i++) {
    printf("%d\n", q[i].ans);
  }
  return 0;
}
