#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, m;
int a[N];
int ans[N];
struct query {
  int ind, k, ri;
  query(int ind = 0, int k = 0, int ri = 0) : ind(ind), k(k), ri(ri){};
  bool operator<(const query &b) const { return k < b.k; }
} q[N];
pair<int, int> b[N];
struct bit {
  int val[N];
  inline void add(int x, int k) {
    for (; x < N; x += (x & (-x))) val[x] += k;
  }
  inline int query(int x) {
    int res = 0;
    for (; x; x -= (x & (-x))) res += val[x];
    return res;
  }
} s;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i), b[i] = pair<int, int>(-a[i], i);
  sort(b + 1, b + n + 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int p1, m1;
    scanf("%d%d", &p1, &m1);
    q[i] = query(m1, p1, i);
  }
  sort(q + 1, q + m + 1);
  int j = 1;
  for (int i = 1; i <= n; ++i) {
    s.add(b[i].second, 1);
    while (j <= m && q[j].k == i) {
      int L = 1, R = n;
      while (L < R) {
        int mid = (L + R) / 2;
        if (s.query(mid) < q[j].ind)
          L = mid + 1;
        else
          R = mid;
      }
      ans[q[j].ri] = a[R];
      ++j;
    }
  }
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
