#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, ar[N], tr[N << 2], val[N << 2];
void update(int id, int v, int x = 1, int l = 1, int r = n) {
  tr[x]++;
  if (l == r) {
    val[x] = v;
    return;
  }
  if (((l + r) >> 1) >= id)
    update(id, v, (x << 1), l, ((l + r) >> 1));
  else
    update(id, v, (x << 1 | 1), ((l + r) >> 1) + 1, r);
}
int query(int k, int x = 1, int l = 1, int r = n) {
  if (l == r) return val[x];
  if (tr[(x << 1)] < k)
    query(k - tr[(x << 1)], (x << 1 | 1), ((l + r) >> 1) + 1, r);
  else
    query(k, (x << 1), l, ((l + r) >> 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<pair<int, int> > ar(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ar[i] = make_pair(-x, i + 1);
  }
  int m;
  cin >> m;
  vector<vector<pair<int, int> > > q(n + 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    q[x].push_back(make_pair(y, i));
  }
  vector<int> ans(m);
  sort(ar.begin(), ar.end());
  for (int i = 0; i < n; i++) {
    update(ar[i].second, -ar[i].first);
    for (auto [k, id] : q[i + 1]) ans[id] = query(k);
  }
  for (auto i : ans) cout << i << '\n';
}
