#include <bits/stdc++.h>
using namespace std;
vector<int> t;
int n;
void init(int nn) {
  n = nn;
  t.assign(n, 0);
}
int sum(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
  return result;
}
void inc(int i, int delta) {
  for (; i < n; i = (i | (i + 1))) t[i] += delta;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
void init(vector<int> a) {
  init((int)a.size());
  for (unsigned i = 0; i < a.size(); i++) inc(i, a[i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int>> a(n), b(n);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[i] = {t, -i};
    b[i] = a[i];
  }
  sort(a.begin(), a.end(), greater<pair<int, int>>());
  init(n);
  int m;
  cin >> m;
  vector<pair<pair<int, int>, int>> q(m);
  for (int i = 0; i < m; i++) {
    cin >> q[i].first.first >> q[i].first.second;
    q[i].second = i;
  }
  sort(q.begin(), q.end());
  vector<int> ans(m);
  int ci = 0;
  for (auto rq : q) {
    while (ci < rq.first.first) {
      inc(-a[ci].second, 1);
      ci++;
    }
    int l = 0, r = n - 1;
    while (l < r) {
      int c = (l + r) / 2;
      if (sum(c) < rq.first.second)
        l = c + 1;
      else
        r = c;
    }
    ans[rq.second] = b[l].first;
  }
  for (auto i : ans) {
    cout << i << " ";
  }
  return 0;
}
