#include <bits/stdc++.h>
using namespace std;
const int NN = 200100;
int a[NN], b[NN], id[NN], p[NN], k[NN], ans[NN];
vector<pair<int, int> > adj[NN];
bool cmp(int u, int v) {
  if (a[u] != a[v]) return a[u] < a[v];
  return u > v;
}
int B[NN];
void update(int u, int first) {
  while (u < NN) {
    B[u] += first;
    u += u & (-u);
  }
}
int calc(int u) {
  int s = 0;
  while (u > 0) {
    s += B[u];
    u -= u & (-u);
  }
  return s;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), id[i] = i;
  sort(id + 1, id + n + 1, cmp);
  reverse(id + 1, id + n + 1);
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", k + i, p + i), adj[k[i]].push_back({i, p[i]});
  for (int i = 1; i <= n; i++) {
    update(id[i], 1);
    for (int j = 0; j < adj[i].size(); j++) {
      int jd = adj[i][j].first, pos = adj[i][j].second;
      int st = 0, ed = NN - 5;
      while (st + 1 < ed) {
        int mid = (st + ed) >> 1;
        if (calc(mid) >= pos)
          ed = mid;
        else
          st = mid;
      }
      ans[jd] = ed;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", a[ans[i]]);
  return 0;
}
