#include <bits/stdc++.h>
using namespace std;
struct BIT {
  int N;
  vector<int> arr;
  BIT(int N) {
    N++;
    this->N = N;
    arr = vector<int>(N);
  }
  void u(int a, int b) {
    _u(a, 1);
    if (b < N) _u(b + 1, -1);
  }
  void _u(int idx, int val) {
    while (idx <= N) {
      arr[idx] += val;
      idx += idx & (-idx);
    }
  }
  int q(int idx) {
    int s = 0;
    while (idx > 0) {
      s += arr[idx];
      idx -= idx & (-idx);
    }
    return s;
  }
};
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> arr(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    arr[i] = i + 1;
  }
  sort(arr.begin(), arr.end(), [&](int i1, int i2) -> bool {
    if (a[i1 - 1] == a[i2 - 1]) return i1 < i2;
    return a[i1 - 1] > a[i2 - 1];
  });
  int M;
  cin >> M;
  vector<vector<int>> qs(M);
  for (int i = 0; i < M; i++) {
    int k, idx;
    cin >> k >> idx;
    qs[i] = {k, idx, i};
  }
  sort(qs.begin(), qs.end());
  BIT bit(N);
  int idx = 0;
  vector<int> ans(M);
  for (int k = 1; k <= N; k++) {
    bit.u(arr[k - 1], N);
    while (idx < M && qs[idx][0] == k) {
      int goal = qs[idx][1];
      int l = 1, r = N;
      while (l < r) {
        int m = (l + r) / 2;
        int am = bit.q(m);
        if (am == goal && (m == 1 || bit.q(m - 1) != goal)) {
          l = m;
          break;
        } else if (am >= goal) {
          r = m - 1;
        } else {
          l = m + 1;
        }
      }
      ans[qs[idx][2]] = a[l - 1];
      idx++;
    }
  }
  for (int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
}
