#include <bits/stdc++.h>
using namespace std;
mt19937 rng(static_cast<unsigned int>(
    chrono::steady_clock::now().time_since_epoch().count()));
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const num_t& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) {
  return a < b ? a = b, true : false;
}
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) {
  return a > b ? a = b, true : false;
}
template <typename num_t>
num_t gcd(const num_t& lhs, const num_t& rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t lcm(const num_t& lhs, const num_t& rhs) {
  return lhs / ::gcd(lhs, rhs) * rhs;
}
template <typename num_t>
num_t pw(num_t n, num_t k, const num_t& mod) {
  if (k == -1) k = mod - 2;
  num_t res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
  }
  return res % mod;
}
const int inf = 1e9 + 7;
const int mod = 998244353;
const long long ll_inf = (long long)inf * inf * 9 + 7;
const int maxn = 150000 + 7;
template <typename num_t, typename merge = plus<num_t>,
          typename split = minus<num_t>>
struct FenWickTree {
  vector<num_t> tree;
  void update(int index, const num_t& value) {
    for (int t = index, max_t = (int)tree.size(); t < max_t; t += t & -t) {
      tree[t] = merge()(tree[t], value);
    }
  }
  num_t get(int index) {
    num_t res = 0;
    for (int t = index; t > 0; t -= t & -t) {
      res = merge()(res, tree[t]);
    }
    return res;
  }
  num_t get(int lhs, int rhs) { return split()(get(rhs), get(lhs - 1)); }
  void init(int n) { tree.resize(n + 1); }
};
FenWickTree<int> fenwick_tree;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  vector<int> id(n);
  iota(id.begin(), id.end(), 0);
  sort(id.begin(), id.end(), [&](int u, int v) -> bool {
    return make_pair(a[u], -u) > make_pair(a[v], -v);
  });
  int m;
  cin >> m;
  vector<vector<pair<int, int>>> query(n + 1);
  for (int i = (0), _b = (m); i < _b; ++i) {
    int k, pos;
    cin >> k >> pos;
    query[k].push_back({i, pos});
  }
  vector<int> ans(m, 0);
  fenwick_tree.init(n + 2);
  for (int k = 1; k <= n; ++k) {
    int cur_pos = id[k - 1] + 1;
    fenwick_tree.update(cur_pos, 1);
    for (auto p : query[k]) {
      int idx = p.first;
      int pos = p.second;
      int start_index = 0;
      for (int j = 19; j >= 0; --j) {
        int nxt = start_index + (1 << j);
        if (nxt < n && fenwick_tree.get(nxt) < pos) start_index = nxt;
      }
      ans[idx] = a[start_index];
    }
  }
  for (auto x : ans) cout << x << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
