#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T>
class fenwick_tree {
 public:
  fenwick_tree(int n_) : n(n_), dat(n, 0) {}
  void add(int i, T value) {
    for (; i < n; i |= i + 1) {
      dat[i] += value;
    }
  }
  T sum(int i) const {
    T res = 0;
    for (; i >= 0; i = (i & (i + 1)) - 1) {
      res += dat[i];
    }
    return res;
  }
  T sum(int l, int r) const { return sum(r - 1) - sum(l - 1); }

 private:
  const int n;
  std::vector<T> dat;
};
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<pair<ll, int>> as(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    as[i] = make_pair(-a[i], i);
  }
  sort(as.begin(), as.end());
  for (auto& p : as) p.first = -p.first;
  int m;
  cin >> m;
  vector<int> ans(m);
  vector<vector<pii>> qs(n + 1);
  for (int i = 0; i < m; ++i) {
    int k, pos;
    cin >> k >> pos;
    qs[k].emplace_back(pos, i);
  }
  fenwick_tree<int> bit(n);
  for (int i = 1; i <= n; ++i) {
    bit.add(as[i - 1].second, 1);
    for (auto const& [pos, qi] : qs[i]) {
      int lb = 0, ub = n + 1;
      while (ub - lb > 1) {
        const int mid = (ub + lb) / 2;
        (bit.sum(0, mid) >= pos ? ub : lb) = mid;
      }
      ans[qi] = a[ub - 1];
    }
  }
  for (int i = 0; i < m; ++i) {
    cout << ans[i] << "\n";
  }
}
