#include <bits/stdc++.h>
using namespace std;
struct bit_tree {
  vector<int> bit;
  int n;
  bit_tree(int n) : n(n + 1) { bit.assign(n + 1, 0); }
  bit_tree(vector<int> a) : bit_tree(a.size()) {
    for (size_t i = 0; i < a.size(); i++) add(i, a[i]);
  }
  int size() { return n - 1; }
  int sum(int idx) {
    int ret = 0;
    for (++idx; idx > 0; idx -= idx & -idx) ret += bit[idx];
    return ret;
  }
  int operator[](int i) { return sum(i); }
  void add(int idx, int delta) {
    for (++idx; idx < n; idx += idx & -idx) bit[idx] += delta;
  }
  int bin_search(int k) {
    int ans = 0, sum = 0;
    for (int j = int(ceil(log2(n))); j >= 0; --j) {
      ans += 1 << j;
      if (ans < n && sum + bit[ans] < k) {
        sum += bit[ans];
      } else {
        ans -= 1 << j;
      }
    }
    return ans + 1 - 1;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  vector<int> oge(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    oge[i] = a;
    v[i] = {a, i};
  }
  sort(v.begin(), v.end(), [&](pair<int, int> a, pair<int, int> b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first > b.first;
  });
  bit_tree fen(2e5 + 2);
  vector<vector<pair<int, int>>> len_to_inds(2e5 + 2);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int len, ind;
    cin >> len >> ind;
    len_to_inds[len].push_back({ind, i});
  }
  vector<int> ans(m, 0);
  for (int i = 0; i < n; i++) {
    fen.add(v[i].second, 1);
    for (auto &[ind, og] : len_to_inds[i + 1]) {
      int inde = fen.bin_search(ind);
      ans[og] = oge[inde];
    }
  }
  for (auto &x : ans) {
    cout << x << '\n';
  }
}
