#include <bits/stdc++.h>
using namespace std;
int n, a[200007], p[200007], fst[200007], m, k, pos;
bool cmp(int x, int y) {
  if (a[x] == a[y]) return x < y;
  return a[x] > a[y];
}
vector<pair<int, int> > v[200007];
int c[200007 * 4];
void add(int k, int l, int r, int x) {
  ++c[k];
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    add(k * 2, l, mid, x);
  else
    add(k * 2 + 1, mid + 1, r, x);
}
int find(int k, int l, int r, int x) {
  if (l == r) return a[l];
  int mid = (l + r) >> 1, cnt = c[k * 2];
  if (x <= cnt)
    return find(k * 2, l, mid, x);
  else
    return find(k * 2 + 1, mid + 1, r, x - cnt);
}
int ans[200007];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) p[i] = i;
  sort(p + 1, p + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (i > 1 && a[p[i]] == a[p[i - 1]])
      fst[i] = fst[i - 1];
    else
      fst[i] = i;
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &k, &pos);
    v[k].push_back(make_pair(i, pos));
  }
  for (int i = 1; i <= n; ++i) {
    add(1, 1, n, p[i]);
    for (pair<int, int> x : v[i]) ans[x.first] = find(1, 1, n, x.second);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
