#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXQ = 200000;
const int MAXS = 4 * MAXN;
int n;
int a[MAXN];
int nq;
int qk[MAXQ], qidx[MAXQ], qans[MAXQ];
pair<int, int> o[MAXN];
vector<int> byk[MAXN + 1];
int sval[MAXS];
void sinit(int x, int l, int r) {
  if (l == r) {
    sval[x] = 0;
  } else {
    int m = l + (r - l) / 2;
    sinit(2 * x + 1, l, m);
    sinit(2 * x + 2, m + 1, r);
    sval[x] = sval[2 * x + 1] + sval[2 * x + 2];
  }
}
void smod(int x, int l, int r, int IDX) {
  if (l == r) {
    ++sval[x];
  } else {
    int m = l + (r - l) / 2;
    if (IDX <= m)
      smod(2 * x + 1, l, m, IDX);
    else
      smod(2 * x + 2, m + 1, r, IDX);
    sval[x] = sval[2 * x + 1] + sval[2 * x + 2];
  }
}
int sget(int x, int l, int r, int OFF) {
  assert(OFF < sval[x]);
  if (l == r) {
    return l;
  } else {
    int m = l + (r - l) / 2;
    if (OFF < sval[2 * x + 1])
      return sget(2 * x + 1, l, m, OFF);
    else
      return sget(2 * x + 2, m + 1, r, OFF - sval[2 * x + 1]);
  }
}
void solve() {
  for (int i = (0); i < (n); ++i) o[i] = make_pair(-a[i], i);
  sort(o, o + n);
  for (int i = (0); i <= (n); ++i) byk[i].clear();
  for (int i = (0); i < (nq); ++i) byk[qk[i]].push_back(i);
  sinit(0, 0, n - 1);
  for (int i = (0); i < (n); ++i) {
    smod(0, 0, n - 1, o[i].second);
    for (int j = (0); j < (((int)(byk[i + 1]).size())); ++j) {
      int id = byk[i + 1][j];
      int idx = sget(0, 0, n - 1, qidx[id]);
      qans[id] = a[idx];
    }
  }
}
void run() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  scanf("%d", &nq);
  for (int i = (0); i < (nq); ++i) scanf("%d%d", &qk[i], &qidx[i]), --qidx[i];
  solve();
  for (int i = (0); i < (nq); ++i) printf("%d\n", qans[i]);
}
int main() {
  run();
  return 0;
}
