#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
struct foo {
  long long val, poz;
};
int n, m;
long long bit[maxn], res[maxn], novi[maxn];
foo niz[maxn];
vector<pair<int, int> > pom[maxn];
bool cmp(foo s1, foo s2) {
  if (s1.val == s2.val) return s1.poz < s2.poz;
  return s1.val > s2.val;
}
void upd(int x, int val) {
  while (x <= maxn) {
    bit[x] += val;
    x += x & (-x);
  }
}
long long query(int x) {
  long long sum = 0;
  while (x > 0) {
    sum += bit[x];
    x -= x & (-x);
  }
  return sum;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> niz[i].val;
    novi[i] = niz[i].val;
    niz[i].poz = i;
  }
  sort(niz + 1, niz + n + 1, cmp);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int k, pos;
    cin >> k >> pos;
    pom[k].push_back({pos, i});
  }
  for (int i = 1; i <= n; i++) {
    upd(niz[i].poz, 1);
    if (pom[i].empty()) continue;
    for (auto f : pom[i]) {
      int x = f.first, ind = f.second;
      int l = 1, r = n, ans;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (query(mid) >= x) {
          ans = mid;
          r = mid - 1;
        } else
          l = mid + 1;
      }
      res[ind] = novi[ans];
    }
  }
  for (int i = 1; i <= m; i++) cout << res[i] << endl;
  return 0;
}
