#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
vector<int> v;
vector<int> ans;
vector<int> got;
vector<pair<int, int> > nums;
vector<pair<int, int> > input;
vector<pair<int, int> > sd;
map<pair<int, int>, int> p, ttl;
void add(int apex, int l, int r, int num, int value) {
  if (num < l || r < num) return;
  v[apex] += value;
  if (l == r) return;
  int m = (l + r) / 2;
  add(apex * 2 + 1, l, m, num, value);
  add(apex * 2 + 2, m + 1, r, num, value);
}
int find(int apex, int l, int r, int num) {
  if (l == r) return l;
  int m = (l + r) / 2;
  if (v[apex * 2 + 1] >= num)
    find(apex * 2 + 1, l, m, num);
  else
    find(apex * 2 + 2, m + 1, r, num - v[apex * 2 + 1]) + m;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    got.push_back(t);
    nums.push_back({t, -i});
  }
  sort(nums.begin(), nums.end());
  reverse(nums.begin(), nums.end());
  for (int i = 0; i < n; i++) {
    nums[i].second *= -1;
  }
  v.resize(4 * n);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    input.push_back({a, b});
    p[{a, b}] = i;
  }
  sd = input;
  sort(sd.begin(), sd.end());
  ans.resize(m);
  int pre = 0;
  for (int i = 0; i < m; i++) {
    int k = sd[i].first;
    int pos = sd[i].second;
    for (int i = pre + 1; i <= k + 1; i++) {
      int w = nums[i - 1].second;
      add(0, 0, n - 1, w, 1);
    }
    pre = k + 1;
    ttl[{k, pos}] = got[find(0, 0, n - 1, pos)];
  }
  for (pair<int, int> q : input) {
    cout << ttl[q] << endl;
  }
  return 0;
}
