#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
class SegTree {
  int n;
  T def;
  function<T(T, T)> operation;
  function<T(T, T)> update;
  vector<T> data;
  T _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return data[k];
    T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
    T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
    return operation(c1, c2);
  }

 public:
  SegTree<T>(int _n, T _def, function<T(T, T)> _operation,
             function<T(T, T)> _update)
      : def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n) n *= 2;
    data = vector<T>(2 * n - 1, def);
  }
  T query(int a, int b) { return _query(a, b, 0, 0, n); }
  void change(int i, T x) {
    i += n - 1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  T operator[](int i) { return data[i + n - 1]; }
};
SegTree<int> sgt(
    200005, 0, [](int a, int b) { return a + b; },
    [](int a, int b) { return b; });
vector<pair<pair<int, int>, int> > req(200005);
int ii;
bool check(int x) {
  if (sgt.query(0, x + 1) >= req[ii].first.second) return 1;
  return 0;
}
template <typename T>
int binary_search(T ok, T ng) {
  while ((ng - ok >= 0 ? ng - ok : -(ng - ok)) > 1) {
    T mid = (ng + ok) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  return ok;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  vector<pair<int, int> > b(n);
  for (int i = 0; i < (n); ++i) {
    b[i].first = -a[i];
    b[i].second = i;
  }
  sort(b.begin(), b.end());
  int m;
  cin >> m;
  for (int i = 0; i < (m); ++i) {
    cin >> req[i].first.first >> req[i].first.second;
    req[i].second = i;
  }
  sort(req.begin(), req.begin() + m);
  int now = 0;
  vector<int> ans(m);
  for (int i = 0; i < (m); ++i) {
    ii = i;
    while (now < req[i].first.first) {
      sgt.change(b[now].second, 1);
      ++now;
    }
    int it = binary_search(n - 1, -1);
    ans[req[i].second] = a[it];
  }
  for (int i = 0; i < (m); ++i) cout << ans[i] << endl;
}
