#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, m, a[N + 10], b[N + 10], ans[N + 10];
int tree[(N + 10) << 2];
struct Position {
  int idx, val;
  bool friend operator<(Position c, Position d) {
    if (c.val != d.val) return !(c.val < d.val);
    return c.idx < d.idx;
  }
} p[N + 10];
struct Node {
  int idx, k, pos;
  bool friend operator<(Node c, Node d) { return c.k < d.k; }
} que[N + 10];
bool cmp(int x, int y) { return x > y; }
void update(int x, int l, int r, int pos) {
  tree[x]++;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (pos <= mid)
    update(x << 1, l, mid, pos);
  else
    update(x << 1 | 1, mid + 1, r, pos);
}
int query(int x, int l, int r, int k) {
  if (l == r) return a[l];
  int mid = (l + r) / 2;
  if (k <= tree[x << 1]) return query(x << 1, l, mid, k);
  return query(x << 1 | 1, mid + 1, r, k - tree[x << 1]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = {i, a[i]};
  }
  sort(p + 1, p + 1 + n);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> que[i].k >> que[i].pos;
    que[i].idx = i;
  }
  sort(que + 1, que + 1 + m);
  int pos = 0;
  for (int i = 1; i <= m; i++) {
    while (pos < que[i].k && pos <= n) {
      pos++;
      update(1, 1, n, p[pos].idx);
    }
    ans[que[i].idx] = query(1, 1, n, que[i].pos);
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
  return 0;
}
