#include <bits/stdc++.h>
using namespace std;
long long int n;
vector<long long int> a, b;
struct segmentTree {
  vector<long long int> t;
  segmentTree() { t.resize(4 * n); }
  void add(long long int ind, long long int x, long long int v = 0,
           long long int tl = 0, long long int tr = n) {
    if (tr - tl == 1)
      t[v] += x;
    else {
      long long int mid = (tl + tr) / 2;
      if (ind >= mid)
        add(ind, x, 2 * v + 2, mid, tr);
      else
        add(ind, x, 2 * v + 1, tl, mid);
      t[v] = t[2 * v + 1] + t[2 * v + 2];
    }
  }
  long long int getK(long long int k, long long int v = 0, long long int tl = 0,
                     long long int tr = n) {
    if (tr - tl == 1)
      return tl;
    else {
      long long int mid = (tl + tr) / 2;
      if (t[2 * v + 1] >= k)
        return getK(k, 2 * v + 1, tl, mid);
      else
        return getK(k - t[2 * v + 1], 2 * v + 2, mid, tr);
    }
  }
};
struct query {
  long long int k, p, ind;
  query(long long int k = 0, long long int p = 0, long long int ind = 0)
      : k(k), p(p), ind(ind) {}
};
signed main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  iota(b.begin(), b.end(), 0);
  for (long long int i = 0; i < n; ++i) cin >> a[i];
  sort(b.begin(), b.end(), [](long long int i, long long int j) {
    return a[i] > a[j] || (a[i] == a[j] && i < j);
  });
  long long int q;
  cin >> q;
  vector<long long int> ans(q);
  vector<query> queries;
  for (long long int i = 0; i < q; ++i) {
    long long int k, p;
    cin >> k >> p;
    queries.emplace_back(k, p, i);
  }
  sort(queries.begin(), queries.end(),
       [](const query& a, const query& b) { return a.k < b.k; });
  long long int last = 0;
  segmentTree t;
  for (auto ev : queries) {
    while (last < ev.k) t.add(b[last++], 1);
    long long int ind = t.getK(ev.p);
    ans[ev.ind] = a[ind];
  }
  for (auto i : ans) cout << i << "\n";
  return 0;
}
