#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct BIT {
 private:
  vector<T> data;
  const int n;

 public:
  BIT(int sz) : data(sz + 1, 0), n(sz) {}
  BIT(vector<T> t) : data(t), n((int)t.size()) {}
  T sum(size_t i) {
    T s = 0;
    while (i > 0) {
      s += data[i];
      i -= i & (-i);
    }
    return s;
  }
  T sum(size_t i, size_t j) { return sum(j) - sum(i); }
  void add(int i, T x) {
    ++i;
    assert(i > 0);
    while (i <= n) {
      data[i] += x;
      i += i & (-i);
    }
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> A(n);
  vector<pair<long long, int>> V;
  for (int i = 0; i < n; ++i) cin >> A[i], V.emplace_back(-A[i], i);
  sort(V.begin(), V.end());
  int m;
  cin >> m;
  vector<int> K(m), P(m);
  vector<vector<int>> I(n);
  for (int i = 0; i < m; ++i) {
    cin >> K[i] >> P[i];
    --K[i], --P[i];
    I[K[i]].push_back(i);
  }
  vector<int> ans(m, -1);
  BIT<int> bit(n + 1);
  for (int i = 0; i < n; ++i) {
    auto p = V[i];
    bit.add(p.second, 1);
    for (auto idx : I[i]) {
      int pos = P[idx];
      int ok = 0, ng = n;
      while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (bit.sum(mid) <= pos)
          ok = mid;
        else
          ng = mid;
      }
      ans[idx] = A[ok];
    }
  }
  for (auto a : ans) cout << a << endl;
}
