#include <bits/stdc++.h>
using namespace std;
int a[200010], ans[200010], t[200010], n, m;
vector<pair<int, int>> req[200010];
void inc(int i, int delta) {
  for (; i < n; i = (i | (i + 1))) t[i] += delta;
}
int sum(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
  return result;
}
int main() {
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) cin >> a[i], v.push_back({a[i], -i});
  sort(v.begin(), v.end());
  cin >> m;
  for (int i = 0; i < m; i++) {
    int k, p;
    cin >> k >> p;
    k--;
    p--;
    req[k].push_back({p, i});
  }
  for (int k = n - 1; k >= 0; k--) {
    for (auto it : req[k]) {
      int l = -1, r = n;
      while (l + 1 < r) {
        int mid = (l + r) / 2;
        if (mid - sum(mid) < it.first)
          l = mid;
        else
          r = mid;
      }
      ans[it.second] = a[r];
    }
    inc(-v[n - k - 1].second, 1);
  }
  for (int i = 0; i < m; i++)
    if (ans[i]) cout << ans[i] << endl;
  return 0;
}
