#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;
}
struct BinaryIndexedTree {
  long long n;
  vector<long long> dat;
  BinaryIndexedTree(long long n = 0) : n(n) { dat.resize(n + 1); }
  void add(long long k, long long x) {
    for (k++; k <= n; k += k & -k) dat[k] += x;
  }
  long long sum(long long k) {
    long long ret = 0;
    for (k++; k; k -= k & -k) ret += dat[k];
    return ret;
  }
};
long long N;
long long A[222222];
vector<long long> lis[222222];
long long Q;
long long K[222222], pos[222222];
signed main() {
  scanf("%lld", &N);
  for (long long i = 0; i < (N); i++) scanf("%lld", &A[i]);
  scanf("%lld", &Q);
  for (long long i = 0; i < (Q); i++)
    scanf("%lld%lld", &K[i], &pos[i]), pos[i]--;
  vector<long long> uku;
  for (long long i = 0; i < (N); i++) uku.push_back(A[i]);
  sort((uku).begin(), (uku).end());
  uku.erase(unique((uku).begin(), (uku).end()), uku.end());
  for (long long i = 0; i < (N); i++)
    A[i] = lower_bound((uku).begin(), (uku).end(), A[i]) - uku.begin();
  for (long long i = 0; i < (N); i++) lis[A[i]].push_back(i);
  long long tmp = 0;
  vector<long long> cnt(N);
  for (long long i = 0; i < (N); i++) cnt[A[i]]++;
  vector<pair<long long, long long> > ev;
  for (long long i = N - 1; i >= 0; i--) {
    tmp += cnt[i];
    ev.emplace_back(tmp, i);
  }
  for (long long i = 0; i < (Q); i++) ev.emplace_back(K[i], i - 1001001001);
  sort((ev).begin(), (ev).end());
  BinaryIndexedTree bit(222222);
  long long now = N - 1;
  long long tot = 0;
  vector<long long> ans(Q);
  for (auto& p : ev) {
    if (p.second >= 0) {
      for (auto& k : lis[p.second]) bit.add(k, 1);
      tot += lis[p.second].size();
      now--;
      continue;
    }
    long long i = p.second + 1001001001;
    long long k = p.first;
    long long lb = 0, ub = N;
    while (ub - lb > 1) {
      long long mid = (ub + lb) / 2;
      long long num = bit.sum(mid - 1);
      long long ptr = lower_bound((lis[now]).begin(), (lis[now]).end(), mid) -
                      lis[now].begin();
      num += min(ptr, k - tot);
      if (num <= pos[i])
        lb = mid;
      else
        ub = mid;
    }
    ans[i] = lb;
  }
  for (long long i = 0; i < (Q); i++) printf("%lld\n", uku[A[ans[i]]]);
  return 0;
}
