#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200001];
pair<int, int> b[200001];
pair<pair<int, int>, int> q[200001];
int ans[200001];
int BITree[200001];
int getSum(int index) {
  int sum = 0;
  while (index > 0) sum += BITree[index], index -= index & (-index);
  return sum;
}
void updateBIT(int index, int val) {
  while (index <= n) BITree[index] += val, index += index & (-index);
}
int wk(int pos) {
  int lo = 1, hi = n, m;
  while (lo < hi) {
    m = (lo + hi) / 2;
    if (getSum(m) < pos)
      lo = m + 1;
    else
      hi = m;
  }
  return lo;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int cur = 0;
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i], b[i] = pair<int, int>(a[i], n - i + 1);
  cin >> m;
  for (i = 1; i <= m; i++)
    cin >> q[i].first.first >> q[i].first.second, q[i].second = i;
  sort(b + 1, b + n + 1);
  sort(q + 1, q + m + 1);
  for (i = 1; i <= m; i++) {
    while (cur < q[i].first.first) {
      updateBIT(n - b[n - cur].second + 1, 1);
      cur++;
    }
    ans[q[i].second] = a[wk(q[i].first.second)];
  }
  for (i = 1; i <= m; i++) cout << ans[i] << endl;
  return 0;
}
