#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int maxn = (2e5 + 10);
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
using namespace std;
struct node {
  int val;
  int id;
} a[maxn];
bool cmp(node a, node b) {
  if (a.val == b.val) {
    return a.id < b.id;
  }
  return a.val > b.val;
}
struct nod {
  int sum;
  int pos;
  int id;
} q[maxn];
bool cmpp(nod a, nod b) { return a.sum < b.sum; }
int ans[maxn];
int tree[maxn * 4];
void push_up(int node) { tree[node] = tree[node << 1] + tree[node << 1 | 1]; }
void update(int node, int start, int end, int val) {
  if (start == end) {
    tree[node] += 1;
    return;
  }
  int mid = (start + end) / 2;
  if (val <= mid) update(node * 2, start, mid, val);
  if (val > mid) update(node * 2 + 1, mid + 1, end, val);
  push_up(node);
}
int query(int node, int start, int end, int k) {
  if (start == end) return start;
  int mid = (start + end) / 2;
  if (tree[node << 1] >= k)
    return query(node * 2, start, mid, k);
  else
    return query(node * 2 + 1, mid + 1, end, k - tree[node << 1]);
}
map<int, int> ys;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    node now;
    now.id = i;
    now.val = x;
    ys[i] = x;
    a[i] = now;
  }
  sort(a + 1, a + 1 + n, cmp);
  int s;
  cin >> s;
  for (int i = 1; i <= s; i++) {
    int x, y;
    cin >> x >> y;
    nod now;
    now.sum = x;
    now.pos = y;
    now.id = i;
    q[i] = now;
  }
  sort(q + 1, q + 1 + s, cmpp);
  int xz = 0;
  for (int i = 1; i <= s; i++) {
    while (xz < q[i].sum) {
      xz += 1;
      update(1, 1, n, a[xz].id);
    }
    int now = query(1, 1, n, q[i].pos);
    ans[q[i].id] = ys[now];
  }
  for (int i = 1; i <= s; i++) cout << ans[i] << endl;
  return 0;
}
