#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 9;
const long long M = 1e3 + 9;
const long long INFINT = 1e9 + 9;
const long long INFLL = 1e18 + 9;
const double EPS = 1e-10;
long long cmp1(pair<long long, long long> a, pair<long long, long long> b) {
  return (a.first < b.first || (a.first == b.first && a.second > b.second));
}
long long cmp2(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
long long p[N];
long long q[N];
vector<long long> t[4 * N];
void build(long long v, long long l, long long r) {
  if (l + 1 == r) {
    t[v].push_back(q[l]);
    return;
  }
  long long m = (l + r) >> 1;
  build(v * 2 + 1, l, m);
  build(v * 2 + 2, m, r);
  merge(t[v * 2 + 1].begin(), t[v * 2 + 1].end(), t[v * 2 + 2].begin(),
        t[v * 2 + 2].end(), back_inserter(t[v]));
}
long long get(long long v, long long tl, long long tr, long long l, long long r,
              long long k) {
  if (tl >= r || tr <= l) return 0;
  if (tl >= l && tr <= r) {
    long long ans = lower_bound(t[v].begin(), t[v].end(), k) - t[v].begin();
    return ans;
  }
  long long tm = (tl + tr) >> 1;
  return get(v * 2 + 1, tl, tm, l, r, k) + get(v * 2 + 2, tm, tr, l, r, k);
}
void solve() {
  vector<pair<long long, long long> > a;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long first;
    cin >> first;
    a.push_back({first, i});
    p[i] = first;
  }
  sort(a.begin(), a.end(), cmp1);
  for (long long i = 0; i < n; i++) q[a[i].second] = i;
  build(0, 0, n);
  long long cnt;
  cin >> cnt;
  for (long long i = 0; i < cnt; i++) {
    long long first, second;
    cin >> first >> second;
    long long k = n - first;
    long long l = 0;
    long long r = n;
    while (l + 1 < r) {
      long long m = (l + r) >> 1;
      if (m - get(0, 0, n, 0, m, k) <= second - 1)
        l = m;
      else
        r = m;
    }
    cout << p[l] << endl;
  }
}
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
}
