#include <bits/stdc++.h>
using namespace std;
void re(int& x);
template <class T>
void re(std::vector<T>& a);
int n, q;
vector<int> a;
vector<pair<pair<int, int>, int> > queries;
int tree[210000];
vector<pair<int, int> > elements;
int ans[210000];
void solve() {
  re(n);
  a.resize(n);
  re(a);
  for (int i = 0; i < n; i++) {
    elements.push_back({-a[i], i + 1});
  }
  sort((elements).begin(), (elements).end());
  re(q);
  for (int i = 0; i < q; i++) {
    int k, pos;
    re(k);
    re(pos);
    queries.push_back({{k, pos}, i});
  }
  sort((queries).begin(), (queries).end());
  int currq = 0;
  for (int i = 1; i <= n; i++) {
    for (int x = elements[i - 1].second; x <= n; x += x & -x) tree[x]++;
    while (currq < q && queries[currq].first.first == i) {
      int pos = queries[currq].first.second;
      int idx = queries[currq].second;
      currq++;
      int st = 1, ed = n;
      while (st < ed) {
        int md = (st + ed) / 2;
        int tot = 0;
        for (int x = md; x > 0; x -= x & -x) tot += tree[x];
        if (tot >= pos)
          ed = md;
        else
          st = md + 1;
      }
      ans[idx] = a[st - 1];
    }
  }
  for (int i = 0; i < q; i++) {
    printf("%d\n", ans[i]);
  }
}
int main() { solve(); }
void re(int& x) { scanf("%d", &x); }
template <class T>
void re(std::vector<T>& a) {
  for (int i = 0; i < a.size(); i++) re(a[i]);
}
