#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A& a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
  if (a < b) a = b;
}
template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
  ost << "{" << p.first << "," << p.second << "}";
  return ost;
}
template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
  ost << "{";
  for (long long i = 0; i < v.size(); i++) {
    if (i) ost << ",";
    ost << v[i];
  }
  ost << "}";
  return ost;
}
template <class T>
struct BinaryIndexedTree {
  long long n;
  vector<T> dat;
  BinaryIndexedTree(long long n = 0) : n(n), dat(n + 1) {}
  void add(long long k, T x) {
    for (k++; k <= n; k += k & -k) dat[k] += x;
  }
  T sum(long long k) {
    T ret{};
    for (k++; k; k -= k & -k) ret += dat[k];
    return ret;
  }
};
long long N;
long long A[222222];
long long K[222222], P[222222];
long long Q;
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (N); i++) scanf("%lld", &A[i]);
  vector<long long> ord(N);
  iota((ord).begin(), (ord).end(), 0);
  sort((ord).begin(), (ord).end(), [&](long long i, long long j) {
    if (A[i] == A[j]) return i < j;
    return A[i] > A[j];
  });
  scanf("%lld", &Q);
  vector<vector<long long> > bucket(N);
  for (long long i = 0; i < (Q); i++) {
    scanf("%lld%lld", &K[i], &P[i]);
    K[i]--;
    P[i]--;
    bucket[K[i]].push_back(i);
  }
  BinaryIndexedTree<long long> bit(N + 114);
  vector<long long> ans(Q);
  for (long long i = 0; i < (N); i++) {
    bit.add(ord[i], 1);
    for (auto j : bucket[i]) {
      long long lb = 0, ub = N;
      while (ub - lb > 1) {
        long long mid = (ub + lb) / 2;
        if (bit.sum(mid - 1) <= P[j])
          lb = mid;
        else
          ub = mid;
      }
      ans[j] = A[lb];
    }
  }
  for (long long i = 0; i < (Q); i++) printf("%lld\n", ans[i]);
  return 0;
}
