#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
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;
  }
};
signed main() {
  long long N;
  scanf("%lld", &N);
  vint A(N);
  for (long long i = 0; i < (N); i++) scanf("%lld", &A[i]);
  vint 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];
  });
  vector<vpint> bucket(N);
  long long Q;
  scanf("%lld", &Q);
  for (long long i = 0; i < (Q); i++) {
    long long k, p;
    scanf("%lld%lld", &k, &p);
    k--;
    p--;
    bucket[k].emplace_back(p, i);
  }
  vint ans(Q);
  BinaryIndexedTree<long long> bit(N + 114);
  for (long long i = 0; i < (N); i++) {
    bit.add(ord[i], 1);
    for (auto& q : bucket[i]) {
      long long lb = 0, ub = N;
      while (ub - lb > 1) {
        long long mid = (ub + lb) / 2;
        if (bit.sum(mid - 1) <= q.first)
          lb = mid;
        else
          ub = mid;
      }
      ans[q.second] = A[lb];
    }
  }
  for (long long i = 0; i < (Q); i++) printf("%lld\n", ans[i]);
  return 0;
}
