#include <bits/stdc++.h>
using namespace std;
const long long MX = 5e5, MOD = 1e9 + 7;
int n, a[MX], m, k, pos, SA[MX];
vector<pair<int, int> > queries[MX];
int ans[MX];
int BIT[MX];
void addValue(int i, int v) {
  for (i++; i <= n; i += i & -i) BIT[i] += v;
}
int getValue(int i) {
  int ans = 0;
  for (i++; i > 0; i -= i & -i) ans += BIT[i];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = int(0); i < int(n); i++) cin >> a[i];
  for (int i = int(0); i < int(n); i++) SA[i] = i, BIT[i] = 0;
  sort(SA, SA + n, [](int i, int j) {
    if (a[i] == a[j]) return i < j;
    return a[i] > a[j];
  });
  cin >> m;
  for (int i = int(0); i < int(m); i++) {
    cin >> k >> pos;
    queries[k - 1].push_back({pos, i});
  }
  for (int i = int(0); i < int(n); i++) {
    addValue(SA[i], 1);
    for (pair<int, int> p : queries[i]) {
      int x = p.first, q = p.second;
      int lb = 0, ub = n - 1;
      while (lb != ub) {
        int mid = (lb + ub) / 2;
        if (getValue(mid) >= x)
          ub = mid;
        else
          lb = mid + 1;
      }
      ans[q] = lb;
    }
  }
  for (int i = int(0); i < int(m); i++) cout << a[ans[i]] << endl;
}
