#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, c[maxn], d[maxn];
long long a[maxn];
pair<int, int> p[maxn];
vector<pair<int, int>> Q[maxn];
void add(int p) {
  for (; p <= n; p += p & -p) {
    c[p]++;
  }
}
int sum(int p) {
  int s = 0;
  for (; p; p -= p & -p) {
    s += c[p];
  }
  return s;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    p[i] = {-a[i], i};
  }
  sort(p + 1, p + n + 1);
  scanf("%d", &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d %d", &x, &y);
    Q[x].push_back({y, i});
  }
  for (int i = 1; i <= n; i++) {
    add(p[i].second);
    for (auto j : Q[i]) {
      int k = j.first, l = 1, r = n, ans;
      while (l <= r) {
        int mid = (l + r) >> 1;
        sum(mid) >= k ? r = (ans = mid) - 1 : l = mid + 1;
      }
      d[j.second] = ans;
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", a[d[i]]);
  }
  return 0;
}
