#include <bits/stdc++.h>
using namespace std;
struct ob {
  int pos, num, l;
};
vector<int> t(2e6), a;
vector<ob> b;
bool comp1(ob a, ob b) {
  if (a.num == b.num) return a.pos < b.pos;
  return a.num > b.num;
}
void update(int v, int tl, int tr, int pos) {
  if (tr == tl) {
    t[v] = 1;
    return;
  }
  int mid = (tr + tl) / 2;
  if (mid < pos) {
    update(v * 2 + 1, mid + 1, tr, pos);
  } else {
    update(v * 2, tl, mid, pos);
  }
  t[v] = t[v * 2] + t[v * 2 + 1];
}
int tfind(int v, int tl, int tr, int pos) {
  if (tr == tl) return a[tl];
  int mid = (tl + tr) / 2;
  if (pos > t[v * 2]) {
    return tfind(v * 2 + 1, mid + 1, tr, pos - t[v * 2]);
  } else {
    return tfind(v * 2, tl, mid, pos);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n;
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i].num = a[i];
    b[i].pos = i;
  }
  cin >> m;
  vector<ob> c(m);
  vector<long long> ans(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> c[i].num >> c[i].l;
    c[i].pos = i;
  }
  sort(b.begin(), b.end(), comp1);
  sort(c.rbegin(), c.rend(), comp1);
  int j = 0;
  for (int i = 0; i < m; i++) {
    while (j < c[i].num) {
      update(1, 0, n - 1, b[j].pos);
      j++;
    }
    ans[c[i].pos] = tfind(1, 0, n - 1, c[i].l);
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << "\n";
  }
}
