#include <bits/stdc++.h>
using namespace std;
class BinTree : vector<int> {
 public:
  explicit BinTree(int k = 0) { assign(k + 1, 0); }
  int lowbit(int k) { return k & -k; }
  int sum(int k) { return k > 0 ? sum(k - lowbit(k)) + (*this)[k] : 0; }
  int last() { return size() - 1; }
  void add(int k, int w) {
    if (k > last()) return;
    (*this)[k] += w;
    add(k + lowbit(k), w);
  }
};
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
bool cmp2(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
int n, m;
vector<int> as;
vector<pair<int, int> > qs;
void solve() {
  BinTree bt(n);
  vector<pair<int, int> > bs;
  for (int i = 1; i <= n; i++) {
    bs.push_back(pair<int, int>(as[i], i));
  }
  sort(bs.begin(), bs.end(), cmp);
  vector<pair<int, int> > qs2 = qs;
  sort(qs2.begin(), qs2.end(), cmp2);
  map<pair<int, int>, int> res;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    pair<int, int> q = qs2[i];
    int k = q.first, p = q.second;
    while (cnt < k) {
      pair<int, int> b = bs[cnt];
      bt.add(b.second, 1);
      cnt++;
    }
    int l = 1, r = n;
    while (l <= r) {
      int m = l + (r - l) / 2;
      int c = bt.sum(m);
      if (c < p)
        l = m + 1;
      else
        r = m - 1;
    }
    res[q] = as[l];
  }
  for (int i = 0; i < m; i++) {
    cout << res[qs[i]] << endl;
  }
}
int main() {
  scanf("%d", &n);
  as = vector<int>(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &as[i]);
  }
  scanf("%d", &m);
  qs = vector<pair<int, int> >(m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &qs[i].first, &qs[i].second);
  }
  solve();
  return 0;
}
