#include <bits/stdc++.h>
using namespace std;
struct node {
  pair<int, int> x;
  int nom;
};
int tree[800010];
vector<node> p;
vector<pair<int, int> > a;
map<int, int> mp;
void update(int v, int tl, int tr, int nom) {
  if (tl == tr) {
    tree[v] = 1;
    return;
  }
  int mid = (tl + tr) / 2;
  if (nom <= mid)
    update(v * 2, tl, mid, nom);
  else
    update(v * 2 + 1, mid + 1, tr, nom);
  tree[v] = tree[v * 2] + tree[v * 2 + 1];
}
int get(int v, int tl, int tr, int nom) {
  if (tl == tr) return mp[tl];
  int mid = (tl + tr) / 2;
  if (nom < tree[v * 2])
    return get(v * 2, tl, mid, nom);
  else
    return get(v * 2 + 1, mid + 1, tr, nom - tree[v * 2]);
}
bool cmp(node z1, node z2) { return z1.x < z2.x; }
bool cmp2(pair<int, int> z1, pair<int, int> z2) {
  if (z1.first != z2.first)
    return z1.first > z2.first;
  else
    return z1.second < z2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back({x, i});
    mp[i] = x;
  }
  sort(a.begin(), a.end(), cmp2);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    p.push_back({{x, y}, i});
  }
  sort(p.begin(), p.end(), cmp);
  int l = 0;
  vector<int> ans(q + 1);
  for (int i = 0; i < q; i++) {
    int k = p[i].x.first;
    int pos = p[i].x.second;
    pos--;
    int nom = p[i].nom;
    for (int j = l; j < k; j++) update(1, 0, n - 1, a[j].second);
    l = k;
    int x = get(1, 0, n - 1, pos);
    ans[nom] = x;
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
