#include <bits/stdc++.h>
using namespace std;
struct segtree {
  long long sz = 262144, a[2 * 262144] = {};
  void update(long long i, long long x, long long lx, long long rx) {
    if (rx - lx == 1) return void(a[x] = 1);
    long long mx = (lx + rx) / 2;
    if (i < mx)
      update(i, 2 * x + 1, lx, mx);
    else
      update(i, 2 * x + 2, mx, rx);
    a[x] = a[2 * x + 1] + a[2 * x + 2];
  }
  void update(long long i) { update(i, 0, 0, sz); }
  long long get(long long i, long long x, long long lx, long long rx) {
    if (rx - lx == 1) return lx;
    long long mx = (lx + rx) / 2;
    if (a[2 * x + 1] >= i)
      return get(i, 2 * x + 1, lx, mx);
    else
      return get(i - a[2 * x + 1], 2 * x + 2, mx, rx);
  }
  long long get(long long i) { return get(i, 0, 0, sz); }
} st;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, m;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  vector<long long> inp(n);
  for (long long i = 0; i < n; ++i) {
    cin >> inp[i];
    a[i] = {-inp[i], i};
  }
  cin >> m;
  long long ans[m];
  vector<array<long long, 3>> b(m);
  for (long long i = 0; i < m; ++i) {
    cin >> b[i][0] >> b[i][1];
    b[i][2] = i;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long done = 0;
  for (auto q : b) {
    while (done < q[0]) st.update(a[done++].second);
    ans[q[2]] = inp[st.get(q[1])];
  }
  for (long long i : ans) cout << i << "\n";
}
