#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
pair<int, int> a[maxn];
int val[maxn * 20], ls[maxn * 20], rs[maxn * 20], tot, cnt[maxn * 20];
int rt[maxn];
void copy(int y, int x) {
  ls[y] = ls[x], rs[y] = rs[x], cnt[y] = cnt[x], val[y] = val[x];
}
void update(int x) { cnt[x] = cnt[ls[x]] + cnt[rs[x]]; }
void insert(int x, int &y, int l, int r, int id, int d) {
  y = ++tot;
  copy(y, x);
  if (l == r) {
    cnt[y] = cnt[x] + 1;
    val[y] = d;
    return;
  }
  int mid = (l + r) >> 1;
  if (id <= mid)
    insert(ls[x], ls[y], l, mid, id, d);
  else
    insert(rs[x], rs[y], mid + 1, r, id, d);
  update(y);
}
int query(int x, int l, int r, int k) {
  if (l == r) return val[x];
  int mid = (l + r) >> 1;
  if (cnt[ls[x]] >= k) return query(ls[x], l, mid, k);
  k -= cnt[ls[x]];
  return query(rs[x], mid + 1, r, k);
}
void init() {
  sort(a + 1, a + n + 1, [](pair<int, int> x, pair<int, int> y) {
    if (x.first == y.first) return x.second < y.second;
    return x.first > y.first;
  });
  for (int i = 1; i <= n; i++) {
    insert(rt[i - 1], rt[i], 1, n, a[i].second, a[i].first);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].first, a[i].second = i;
  init();
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int k, pos;
    cin >> k >> pos;
    cout << query(rt[k], 1, n, pos) << "\n";
  }
}
