#include <bits/stdc++.h>
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int N = 2e5 + 5;
int n;
priority_queue<pair<int, int> > pq;
int dat[N], a[N], res[N];
vector<pair<int, int> > vq[N];
inline void add(int x) {
  ++x;
  while (x < N) {
    dat[x]++;
    x += x & -x;
  }
}
inline int qry(int x) {
  ++x;
  int ans = 0;
  while (x) {
    ans += dat[x];
    x -= x & -x;
  }
  return ans;
}
int main() {
  n = getint();
  for (int(i) = 0; (i) < (n); (i)++) {
    int x = getint();
    a[i] = x;
    pq.push(make_pair(x, -i));
  }
  int q = getint();
  for (int(i) = 0; (i) < (q); (i)++) {
    int x = getint(), y = getint();
    vq[x].push_back(make_pair(y, i));
  }
  for (int i = 1; i <= n; i++) {
    pair<int, int> u = pq.top();
    pq.pop();
    add(-u.second);
    for (int(j) = 0; (j) < (vq[i].size()); (j)++) {
      int lb = -1, rb = n - 1;
      while (rb - lb > 1) {
        int mid = (lb + rb) >> 1;
        if (qry(mid) >= vq[i][j].first) {
          rb = mid;
        } else
          lb = mid;
      }
      res[vq[i][j].second] = a[rb];
    }
  }
  for (int(i) = 0; (i) < (q); (i)++) printf("%d\n", res[i]);
  return 0;
}
