#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
int addm(int& a, int b) { return (a += b) < mod ? a : a -= mod; }
template <class T, class U>
bool smin(T& a, U b) {
  return a > b ? (a = b, 1) : 0;
}
template <class T, class U>
bool smax(T& a, U b) {
  return a < b ? (a = b, 1) : 0;
}
template <typename T>
struct FenwickTree {
  int N;
  vector<T> A;
  FenwickTree(int n) : N(n + 1), A(N) {}
  T rq(int b) {
    T r = 0;
    for (; b; b -= b & -b) r += A[b];
    return r;
  }
  T rq(int a, int b) { return rq(b) - rq(a); }
  void adjust(int i, T v) {
    for (i++; i < N; i += i & -i) A[i] += v;
  }
  int lower_bound(T sum) {
    int i = 0;
    for (int b = 1 << (31 - __builtin_clz(N)); b; b /= 2)
      if (i + b < N && sum > A[i + b]) sum -= A[i + b], i += b;
    return i;
  }
};
int n, m;
int a[200000];
int kj[200000], posj[200000];
int ans[200000], ord[200000];
int asort[200000];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  iota(asort, asort + n, 0);
  sort(asort, asort + n,
       [](int i, int j) { return a[i] > a[j] || (a[i] == a[j] && i < j); });
  cin >> m;
  for (int i = 0; i < m; ++i) cin >> kj[i] >> posj[i];
  iota(ord, ord + m, 0);
  sort(ord, ord + m, [](int i, int j) { return kj[i] < kj[j]; });
  FenwickTree<int> ft(n);
  for (int i = 0, j = 0; i < n; ++i) {
    ft.adjust(asort[i], 1);
    while (j < m && kj[ord[j]] == i + 1) {
      ans[ord[j]] = a[ft.lower_bound(posj[ord[j]])];
      ++j;
    }
  }
  for (int i = 0; i < m; ++i) cout << ans[i] << '\n';
}
