#include <bits/stdc++.h>
using namespace std;
const int maxn = 200001;
struct req {
  int k, p, id;
  req() {}
  req(int k, int p, int id) : k(k), p(p), id(id) {}
  bool operator<(const req &r) const { return k < r.k; }
};
int n, m;
int a[maxn];
int p[maxn];
req q[maxn];
int ans[maxn];
bool cmp(int i, int j) {
  if (a[i] != a[j]) return a[i] > a[j];
  return i < j;
}
void change(int x, int d);
int cal(int x);
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 + 1 + n, cmp);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &q[i].k, &q[i].p);
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m);
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    change(p[i], 1);
    while (cur < m && q[cur + 1].k == i) {
      cur++;
      ans[q[cur].id] = cal(q[cur].p);
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", a[ans[i]]);
  }
  return 0;
}
int low_bit(int x) { return x & -x; }
int b[maxn];
void change(int x, int d) {
  for (int i = x; i <= n; i += low_bit(i)) {
    b[i] += d;
  }
}
int cal(int x) {
  int ans = 0;
  int cur = 0;
  for (int i = 21; i >= 0; i--) {
    if (ans + (1 << i) > n) continue;
    if (cur + b[ans + (1 << i)] < x) {
      ans += (1 << i);
      cur += b[ans];
    }
  }
  return ans + 1;
}
