#include <bits/stdc++.h>
using namespace std;
struct ft {
  int n;
  vector<int> t;
  ft(int sz) {
    n = sz;
    t.resize(2 * n);
  }
  void upd(int pos, int val) {
    ++pos;
    while (pos <= n) {
      t[pos] += val;
      pos += pos & (-pos);
    }
  }
  int qry(int pos) {
    int ans = 0;
    while (pos) {
      ans += t[pos];
      pos -= pos & (-pos);
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n], take[n];
  map<int, list<int>> at;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    take[i] = a[i];
    at[a[i]].push_back(i);
  }
  int m;
  cin >> m;
  pair<pair<int, int>, int> qry[m];
  int ans[m];
  for (int i = 0; i < m; i++) {
    cin >> qry[i].first.first >> qry[i].first.second;
    qry[i].second = i;
  }
  sort(qry, qry + m);
  sort(take, take + n, greater<int>());
  int idx = 0;
  ft fa(n);
  for (int i = 0; i < m; i++) {
    int dist = qry[i].first.first;
    if (i) dist = qry[i].first.first - qry[i - 1].first.first;
    for (int i = 0; i < dist; i++, idx++) {
      auto it = at.find(take[idx]);
      int pos = it->second.front();
      it->second.pop_front();
      fa.upd(pos, 1);
    }
    int l = 1, r = n;
    while (l <= r) {
      int mid = (l + r) / 2;
      int cur = fa.qry(mid);
      if (cur < qry[i].first.second) {
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    ans[qry[i].second] = a[l - 1];
  }
  for (int x : ans) cout << x << '\n';
}
