#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 9;
int tree[N * 4 + 512];
void inc(int node, int cl, int cr, int p) {
  tree[node]++;
  if (cl == cr) return;
  int mid = (cl + cr) / 2;
  if (mid >= p)
    inc(node * 2, cl, mid, p);
  else
    inc(node * 2 + 1, mid + 1, cr, p);
}
int ask(int node, int cl, int cr, int rq) {
  if (cl == cr) return cl;
  int mid = (cl + cr) / 2;
  if (tree[node * 2] >= rq) {
    return ask(node * 2, cl, mid, rq);
  } else {
    return ask(node * 2 + 1, mid + 1, cr, rq - tree[node * 2]);
  }
}
vector<pair<int, int> > qq[N];
int res[N];
int a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<pair<int, int> > ind;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ind.push_back(make_pair(a[i], -i));
  }
  sort(ind.begin(), ind.end());
  int q;
  cin >> q;
  int k, p;
  for (int i = 0; i < q; i++) {
    cin >> k >> p;
    qq[k].push_back(make_pair(p, i));
  }
  int comp = 1;
  for (int j = n - 1; j >= 0; j--) {
    inc(1, 1, n, -ind[j].second);
    for (auto x : qq[comp]) {
      res[x.second] = a[ask(1, 1, n, x.first)];
    }
    comp++;
  }
  for (int i = 0; i < q; i++) cout << res[i] << "\n";
  return 0;
}
