#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
struct node {
  int id, x;
  bool operator<(const node& t) const {
    if (x == t.x) return id > t.id;
    return x < t.x;
  }
};
struct Query {
  int id, k, pos;
  bool operator<(const Query& t) const {
    if (k == t.k) return pos < t.pos;
    return k < t.k;
  }
} q[N];
int n, m;
int a[N];
int ans[N];
int tr[N];
int lowbit(int x) { return x & -x; }
void add(int x, int d) {
  for (int i = x; i <= n; i += lowbit(i)) tr[i] += d;
}
int sum(int x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += tr[i];
  return res;
}
int f[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  priority_queue<node> pq;
  for (int i = 1; i <= n; i++) pq.push({i, a[i]});
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int k, pos;
    cin >> k >> pos;
    q[i] = {i, k, pos};
  }
  sort(q + 1, q + 1 + m);
  int k = 0, pos = 0;
  for (int i = 1; i <= m; i++) {
    while (q[i].k > k) {
      node t = pq.top();
      pq.pop();
      f[t.id] = t.x;
      add(t.id, 1);
      k++;
    }
    int l = 1, r = n;
    while (l < r) {
      int mid = l + r >> 1;
      if (sum(mid) >= q[i].pos)
        r = mid;
      else
        l = mid + 1;
    }
    ans[q[i].id] = f[l];
  }
  for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
  return 0;
}
