#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
void DEBUG(string label, T value) {
  cerr << "[" << label << " = " << value << "]\n";
}
class SegmentTree {
  const int n = 2e5 + 10;
  vector<int> st;

 public:
  SegmentTree() { st.resize(4 * n); }
  void update(int v, int tl, int tr, int pos) {
    if (tl == tr) {
      st[v] = 1;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm) {
        update(2 * v, tl, tm, pos);
      } else {
        update(2 * v + 1, tm + 1, tr, pos);
      }
      st[v] = st[2 * v] + st[2 * v + 1];
    }
  }
  int find_kth(int v, int tl, int tr, int k) {
    if (k > st[v]) {
      return -1;
    }
    if (tl == tr) {
      return tl;
    }
    int tm = (tl + tr) / 2;
    if (k <= st[2 * v]) {
      return find_kth(2 * v, tl, tm, k);
    } else {
      return find_kth(2 * v + 1, tm + 1, tr, k - st[2 * v]);
    }
  }
};
void solve() {
  int n, q;
  cin >> n;
  vector<pair<int, int>> arr(n);
  vector<int> original_array(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first;
    arr[i].second = i;
    original_array[i] = arr[i].first;
  }
  sort(arr.begin(), arr.end(),
       [](const pair<int, int> &lhs, const pair<int, int> &rhs) -> bool {
         if (lhs.first != rhs.first) return lhs.first > rhs.first;
         return lhs.second < rhs.second;
       });
  cin >> q;
  vector<pair<pair<int, int>, int>> queries(q);
  for (int i = 0; i < q; ++i) {
    int k, p;
    cin >> k >> p;
    queries[i] = {{k, p}, i};
  }
  sort(queries.begin(), queries.end());
  int last = 0;
  vector<int> ans(q);
  SegmentTree st;
  const int N = 2e5 + 10;
  for (int i = 0; i < q; ++i) {
    int k = queries[i].first.first;
    int p = queries[i].first.second;
    int idx = queries[i].second;
    while (last < k) {
      st.update(1, 0, N, arr[last].second);
      last++;
    }
    int pos = st.find_kth(1, 0, N, p);
    ans[idx] = original_array[pos];
  }
  for (auto i : ans) {
    cout << i << '\n';
  }
}
int main(int argv, char **argc) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
