#include <bits/stdc++.h>
using namespace std;
int ans[200005], tree[200005], b[200005], n, m;
pair<pair<int, int>, int> req[200005];
pair<int, int> a[200005];
void upd(int i) {
  for (int j = i; j <= n; j += j & (-j)) {
    tree[j]++;
  }
}
int sum(int i) {
  int res = 0;
  for (int j = i; j; j -= j & (-j)) {
    res += tree[j];
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    b[i] = a[i].first;
    a[i].second = i;
  }
  sort(a, a + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
    return p1.first == p2.first ? p1.second < p2.second : p1.first > p2.first;
  });
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> req[i].first.first >> req[i].first.second;
    req[i].second = i;
  }
  sort(req, req + m);
  int cur = 0;
  for (int i = 0; i < m; i++) {
    int k, pos;
    tie(k, pos) = req[i].first;
    while (cur < k) {
      upd(a[cur].second + 1);
      cur++;
    }
    int l = 0, r = n;
    while (l + 1 < r) {
      int mid = (l + r - 1) / 2;
      if (sum(mid + 1) >= pos)
        r = mid + 1;
      else
        l = mid + 1;
    }
    ans[req[i].second] = b[l];
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
