#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
const int N = 262144;
int t, n, m, k, pos;
vector<int> arr, ans;
vector<pair<int, int>> brr;
vector<pair<pair<int, int>, int>> mrr;
vector<int> prr(2 * N, 0);
int power(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y >>= 1;
    x = x * x;
  }
  return res;
}
void ins(int v) {
  for (int i = N + v; i > 0; i /= 2) {
    prr[i]++;
  }
}
int get(int ind, int v, int l, int r) {
  if (r - l == 1) return l;
  if (prr[v * 2] >= ind)
    return get(ind, v * 2, l, (l + r) / 2);
  else
    return get(ind - prr[v * 2], 2 * v + 1, (l + r) / 2, r);
}
void solve() {
  cin >> n;
  arr.resize(n), brr.resize(n);
  ;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  };
  for (int i = 0; i < n; i++) {
    brr[i].first = -arr[i], brr[i].second = i;
  }
  sort(brr.begin(), brr.end());
  cin >> m;
  ans.resize(m), mrr.resize(m);
  ;
  for (int i = 0; i < m; i++) {
    cin >> mrr[i].first.first >> mrr[i].first.second;
    mrr[i].second = i;
  }
  sort(mrr.begin(), mrr.end());
  int len = 0;
  ;
  for (int i = 0; i < m; i++) {
    while (len < mrr[i].first.first) {
      ins(brr[len].second);
      len++;
    }
    ans[mrr[i].second] = arr[get(mrr[i].first.second, 1, 0, N)];
  };
  for (int i = 0; i < m; i++) cout << ans[i] << "\n";
}
int32_t main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  t = 1;
  while (t--) {
    solve();
  }
}
