#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 666666;
int n, m, a[N], ans[N], v[N], id[N];
vector<pair<int, int> > que[N];
void add(int p, int x) {
  while (p <= n) v[p] += x, p += p & -p;
}
int qry(int p) {
  int r = 0;
  while (p) r += v[p], p -= p & -p;
  return r;
}
bool cmp(int x, int y) { return a[x] != a[y] ? a[x] > a[y] : x < y; }
int main() {
  read(n);
  for (register int i = (1); i <= (n); i++) read(a[i]), id[i] = i;
  read(m);
  for (register int i = (1); i <= (m); i++) {
    int k, p;
    read(k);
    read(p);
    que[k].push_back(pair<int, int>(p, i));
  }
  sort(id + 1, id + n + 1, cmp);
  for (register int t = (1); t <= (n); t++) {
    add(id[t], 1);
    for (register int i = (0); i <= (((int)que[t].size()) - 1); i++) {
      int k = que[t][i].first, l = 1, r = n;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (qry(mid) < k)
          l = mid + 1;
        else
          ans[que[t][i].second] = mid, r = mid - 1;
      }
    }
  }
  for (register int i = (1); i <= (m); i++) printf("%d\n", a[ans[i]]);
  return 0;
}
