#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323;
const long long mod = 1000000000 + 7;
const long long INF = 1e18;
const long long P1 = 317;
const long long P2 = 239;
const long long N = 2e5;
const double kd = 1.41421356237;
vector<int> tree;
void Set(int v, int L, int R, int pos) {
  if (R - L == 1) {
    tree[v] = 1;
    return;
  }
  if (pos < (L + R) / 2)
    Set(v * 2, L, (L + R) / 2, pos);
  else
    Set(v * 2 + 1, (L + R) / 2, R, pos);
  tree[v] = tree[v * 2] + tree[v * 2 + 1];
}
pair<int, int> Get(int v, int L, int R, int k) {
  if (tree[v] < k) return {tree[v], -1};
  if (R - L == 1) return {1, L};
  pair<int, int> an1 = Get(v * 2, L, (L + R) / 2, k), an2;
  if (an1.first < k) {
    an2 = Get(v * 2 + 1, (L + R) / 2, R, k - an1.first);
    return {an2.first + an1.first, an2.second};
  }
  return an1;
}
int an[N];
pair<pair<int, int>, int> b[N];
int ff(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
int ff2(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, mm;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  tree.resize(n * 4);
  cin >> mm;
  for (int i = 0; i < mm; i++) {
    cin >> b[i].first.first >> b[i].first.second;
    b[i].second = i;
  }
  sort(b, b + mm);
  sort(a.begin(), a.end(), ff);
  int j = 0, kk = 1;
  for (int i = 0; i < n; i++) {
    int x = a[i].second;
    Set(1, 0, n, x);
    while (b[j].first.first == kk) {
      int pos = b[j].first.second;
      int qq = b[j].second;
      j++;
      an[qq] = Get(1, 0, n, pos).second;
    }
    kk++;
  }
  sort(a.begin(), a.end(), ff2);
  for (int i = 0; i < mm; i++) cout << a[an[i]].first << '\n';
}
