#include <bits/stdc++.h>
using namespace std;
int n, h, k, i, x, y, t[800000];
vector<int> v1;
vector<pair<int, int>> v, v2;
vector<pair<pair<int, int>, int>> q;
bool comp(pair<int, int> a, pair<int, int> b) {
  return a.second > b.second || a.second == b.second && a.first < b.first;
}
bool comp1(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
void build(int p, int l, int r) {
  if (l + 1 == r) {
    t[p] = 0;
    return;
  }
  int m = (l + r) / 2;
  build(2 * p + 1, l, m);
  build(2 * p + 2, m, r);
  t[p] = t[2 * p + 1] + t[2 * p + 2];
}
void update(int p, int l, int r, int index, int v = 1) {
  if (index < l || r <= index) return;
  if (l + 1 == r) {
    t[p] = v;
    return;
  }
  int m = (l + r) / 2;
  update(2 * p + 1, l, m, index, v);
  update(2 * p + 2, m, r, index, v);
  t[p] = t[2 * p + 1] + t[2 * p + 2];
}
void get(int l, int r, int index, int v) {
  int p = 0, s = 0;
  while (l + 1 < r) {
    if (t[2 * p + 1] + s >= v) {
      p = 2 * p + 1;
      r = (l + r) / 2;
    } else {
      s += t[2 * p + 1];
      p = 2 * p + 2;
      l = (l + r) / 2;
    }
  }
  v2.push_back({index, l});
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    v.push_back({i, x});
    v1.push_back(x);
  }
  sort(v.begin(), v.end(), comp);
  cin >> h;
  for (int j = 0; j < h; j++) {
    cin >> x >> y;
    q.push_back({{x, y}, j});
  }
  sort(q.begin(), q.end());
  build(0, 0, n);
  k = 0;
  for (int j = 0; j < h; j++) {
    while (k < q[j].first.first) {
      update(0, 0, n, v[k].first);
      k++;
    }
    get(0, n, q[j].second, q[j].first.second);
  }
  sort(v2.begin(), v2.end(), comp1);
  for (int j = 0; j < h; j++) cout << v1[v2[j].second] << endl;
  return 0;
}
