#include <bits/stdc++.h>
using namespace std;
int n, a[200010];
vector<pair<int, int>> o;
int m;
vector<pair<pair<int, int>, int>> q;
int ans[200010];
int bit[200010];
void add(int x, int val) {
  for (; x <= n; x += x & -x) bit[x] += val;
}
int get(int x) {
  int res = 0;
  for (; x > 0; x -= x & -x) res += bit[x];
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    o.push_back(make_pair(-a[i], i));
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int k, pos;
    cin >> k >> pos;
    q.push_back(make_pair(make_pair(k, pos), i));
  }
  sort(o.begin(), o.end());
  sort(q.begin(), q.end());
  int curk = 0;
  for (auto& qq : q) {
    int k = qq.first.first;
    int pos = qq.first.second;
    int i = qq.second;
    while (curk < k) {
      int j = o[curk].second;
      add(j, 1);
      curk++;
    }
    int lo = 0, hi = n, mid;
    while (hi - lo > 1) {
      mid = (lo + hi) / 2;
      if (get(mid) < pos)
        lo = mid;
      else
        hi = mid;
    }
    ans[i] = a[hi];
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
}
