#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
long long SEED = 1e6 + 3;
long long mod = 1e9;
struct Node {
  long long x, y, s;
  Node *left, *right;
  Node() {}
  Node(long long val) {
    s = 1;
    x = val;
    y = rand();
    left = nullptr;
    right = nullptr;
  }
  ~Node() {
    if (left) delete left;
    if (right) delete right;
  }
};
long long get_size(Node *root) {
  if (root) return root->s;
  return 0;
}
void update(Node *root) {
  if (!root) return;
  root->s = 1 + get_size(root->left) + get_size(root->right);
}
bool find_e(Node *root, long long key) {
  if (!root) return false;
  if (root->x == key)
    return true;
  else if (root->x > key)
    return find_e(root->left, key);
  else
    return find_e(root->right, key);
}
pair<Node *, Node *> split(Node *root, long long key) {
  if (!root) return {nullptr, nullptr};
  if (root->x <= key) {
    pair<Node *, Node *> roots;
    roots = split(root->right, key);
    root->right = roots.first;
    update(root);
    return {root, roots.second};
  } else {
    pair<Node *, Node *> roots;
    roots = split(root->left, key);
    root->left = roots.second;
    update(root);
    return {roots.first, root};
  }
}
Node *merge_e(Node *root1, Node *root2) {
  if (!root1) return root2;
  if (!root2) return root1;
  if (root1->y > root2->y) {
    root1->right = merge_e(root1->right, root2);
    update(root1);
    return root1;
  } else {
    root2->left = merge_e(root1, root2->left);
    update(root2);
    return root2;
  }
}
Node *insert_e(Node *root, long long key) {
  if (find_e(root, key)) return root;
  pair<Node *, Node *> roots = split(root, key);
  Node *root2 = new Node(key);
  return merge_e(merge_e(roots.first, root2), roots.second);
}
long long get_k(Node *root, long long k) {
  long long s1 = get_size(root->left);
  if (k == s1)
    return root->x;
  else if (k < s1)
    return get_k(root->left, k);
  else
    return get_k(root->right, k - s1 - 1);
}
int32_t main() {
  srand(SEED);
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<vector<long long>> pr(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long m;
  cin >> m;
  vector<vector<long long>> q(m, vector<long long>(3));
  vector<vector<long long>> l(n, vector<long long>(2));
  for (long long i = 0; i < m; i++) {
    cin >> q[i][0] >> q[i][1];
    q[i][2] = i;
  }
  sort(q.begin(), q.end());
  for (long long i = 0; i < n; i++) {
    l[i][0] = a[i];
    l[i][1] = -i;
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  vector<long long> ans(m);
  long long j = 0;
  Node *root = nullptr;
  for (long long i = 0; i < m; i++) {
    long long now_k = q[i][0], now_pos = q[i][1];
    now_k--;
    now_pos--;
    while (j <= now_k) {
      root = insert_e(root, -l[j][1]);
      j++;
    }
    long long lans = get_k(root, now_pos);
    ans[q[i][2]] = a[lans];
  }
  for (auto v : ans) cout << v << "\n";
  return 0;
}
