#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
using ll = long long;
pair<ll, int> a[maxn];
ll b[maxn];
struct NODE {
  NODE *left, *right;
  int val;
  NODE() {
    left = nullptr;
    right = nullptr;
    val = 0;
  }
} * root[maxn];
void build(NODE *node, int b, int e) {
  if (b == e) {
    node->val = 0;
    return;
  }
  int mid = (b + e) >> 1;
  if (node->left == nullptr) node->left = new NODE();
  if (node->right == nullptr) node->right = new NODE();
  build(node->left, b, mid);
  build(node->right, mid + 1, e);
  node->val = node->left->val + node->right->val;
}
void upd(NODE *prv, NODE *cur, int b, int e, int idx) {
  if (idx > e || idx < b) return;
  if (idx == b && idx == e) {
    cur->val = prv->val + 1;
    return;
  }
  int mid = (b + e) >> 1;
  if (idx <= mid) {
    if (cur->left == nullptr) cur->left = new NODE();
    cur->right = prv->right;
    upd(prv->left, cur->left, b, mid, idx);
  } else {
    if (cur->right == nullptr) cur->right = new NODE();
    cur->left = prv->left;
    upd(prv->right, cur->right, mid + 1, e, idx);
  }
  cur->val = cur->left->val + cur->right->val;
}
int query(NODE *prv, NODE *cur, int b, int e, int k) {
  if (b == e) return b;
  int mid = (b + e) >> 1;
  if (k <= cur->left->val - prv->left->val)
    return query(prv->left, cur->left, b, mid, k);
  else {
    return query(prv->right, cur->right, mid + 1, e,
                 k - (cur->left->val - prv->left->val));
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i].first);
    b[i] = a[i].first;
    a[i].second = i;
  }
  sort(a + 1, a + n + 1, [&](pair<ll, int> x, pair<ll, int> y) {
    if (x.first != y.first)
      return x.first > y.first;
    else
      return x.second < y.second;
  });
  root[0] = new NODE();
  build(root[0], 1, n);
  for (int i = 1; i <= n; ++i) {
    root[i] = new NODE();
    upd(root[i - 1], root[i], 1, n, a[i].second);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int k, pos;
    scanf("%d %d", &k, &pos);
    printf("%lld\n", b[query(root[0], root[k], 1, n, pos)]);
  }
  return 0;
}
