#include <bits/stdc++.h>
using namespace std;
void setIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("1227D"
            ".inp",
            "r")) {
    freopen(
        "1227D"
        ".inp",
        "r", stdin);
    freopen(
        "1227D"
        ".out",
        "w", stdout);
  }
}
const int N = 2e5 + 2;
int n, m, res[N], st[N * 4], c[N];
pair<int, int> a[N];
pair<pair<int, int>, int> b[N];
void readinp() {
  cin >> n;
  for (int i = int(1); i <= int(n); i++) cin >> a[i].first, a[i].second = i;
  cin >> m;
  for (int i = int(1); i <= int(m); i++)
    cin >> b[i].first.first >> b[i].first.second, b[i].second = i;
}
bool cmp(pair<int, int> t1, pair<int, int> t2) {
  if (t1.first != t2.first) return t1.first > t2.first;
  return t1.second < t2.second;
}
void upd(int id, int l, int r, int p, int v) {
  if (l == r) {
    st[id] += v;
    return;
  }
  int mid = (l + r) / 2;
  if (p >= mid + 1)
    upd(id * 2 + 1, mid + 1, r, p, v);
  else
    upd(id * 2, l, mid, p, v);
  st[id] = st[id * 2] + st[id * 2 + 1];
}
int get(int id, int l, int r, int v) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  if (v > st[id * 2])
    return get(id * 2 + 1, mid + 1, r, v - st[id * 2]);
  else
    return get(id * 2, l, mid, v);
}
void solve() {
  for (int i = int(1); i <= int(n); i++) c[i] = a[i].first;
  sort(a + 1, a + 1 + n, cmp);
  sort(b + 1, b + 1 + m);
  int j = 0;
  for (int i = int(1); i <= int(m); i++) {
    for (int d = int(j + 1); d <= int(b[i].first.first); d++)
      upd(1, 1, n, a[d].second, 1);
    j = b[i].first.first;
    res[b[i].second] = c[get(1, 1, n, b[i].first.second)];
  }
  for (int i = int(1); i <= int(m); i++) cout << res[i], cout << endl;
}
int main() {
  setIO();
  int t = 1;
  while (t--) {
    readinp();
    solve();
  }
}
