#include <bits/stdc++.h>
using namespace std;
struct query {
  int k, pos, id;
};
const int N = 2e5 + 10;
pair<int, int> a[N];
query q[N];
int b[N], C[N], ans[N];
int n;
int lowbit(int x) { return x & -x; }
void add(int x, int d) {
  while (x <= n) {
    C[x] += d;
    x += lowbit(x);
  }
}
int sum(int x) {
  int ret = 0;
  while (x) {
    ret += C[x];
    x -= lowbit(x);
  }
  return ret;
}
int main() {
  int m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    a[i] = {b[i], i};
  }
  sort(a + 1, a + n + 1, [&](pair<int, int> x, pair<int, int> y) {
    if (x.first == y.first) {
      return x.second < y.second;
    }
    return x.first > y.first;
  });
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &q[i].k, &q[i].pos);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1, [&](query x, query y) { return x.k < y.k; });
  for (int i = 1, j = 0; i <= n; i++) {
    add(a[i].second, 1);
    while (j < m && q[j + 1].k == i) {
      int l = 0, r = n + 1;
      while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (sum(mid) < q[j + 1].pos)
          l = mid;
        else
          r = mid;
      }
      ans[q[j + 1].id] = b[r];
      j++;
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
