#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
int ans[N];
struct Data {
  int d;
  int num;
} a[N];
int x[N];
struct Que {
  int pos;
  int index;
  int num;
} q[N];
int c[N];
int lowbit(int x) { return x & (-x); }
void Add(int i) {
  for (int j = i; j <= n; j += lowbit(j)) c[j]++;
}
int Find(int i) {
  int ans = 0;
  for (int j = i; j > 0; j -= lowbit(j)) ans += c[j];
  return ans;
}
bool cmp(Data a, Data b) {
  if (a.d != b.d)
    return a.d > b.d;
  else
    return a.num < b.num;
}
bool cmpp(Que a, Que b) { return a.num < b.num; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    a[i].num = i;
    a[i].d = x[i];
  }
  sort(a + 1, a + 1 + n, cmp);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int num, pos;
    scanf("%d %d", &num, &pos);
    q[i].num = num;
    q[i].pos = pos;
    q[i].index = i;
  }
  sort(q + 1, q + 1 + m, cmpp);
  int j = 0;
  for (int i = 1; i <= m; i++) {
    while (j + 1 <= q[i].num) {
      j++;
      Add(a[j].num);
    }
    int l = 1, r = n, mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (Find(mid) >= q[i].pos)
        r = mid;
      else
        l = mid + 1;
    }
    ans[q[i].index] = x[l];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
