#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 2e5 + 10;
const int M = 1e4 + 10;
const int maxn = 1e6 + 10;
const int mod = (int)1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct Node {
  int v, p;
  bool operator<(const Node &A) const {
    if (v ^ A.v) return v > A.v;
    return p < A.p;
  }
} a[N];
struct Node2 {
  int k, pos, id;
  bool operator<(const Node2 &A) const { return k < A.k; }
} b[N];
int n, m;
int v[N];
int c[N];
int ans[N];
void add(int x) {
  while (x < N) {
    c[x]++;
    x += ((x) & -(x));
  }
}
int sum(int x) {
  int res = 0;
  while (x) {
    res += c[x];
    x -= ((x) & -(x));
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    a[i] = {v[i], i};
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> b[i].k >> b[i].pos;
    b[i].id = i;
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  for (int i = 1, j = 1; i <= n; i++) {
    add(a[i].p);
    while (j <= m && b[j].k == i) {
      int l = 1, r = n, pos = 0;
      while (l <= r) {
        int mid = ((l + r) >> 1);
        if (sum(mid) >= b[j].pos)
          r = mid - 1, pos = mid;
        else
          l = mid + 1;
      }
      ans[b[j++].id] = v[pos];
    }
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
  return 0;
}
