#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> t;
int query(int v, int l, int r, int vl, int vr, int k) {
  if (l > vr || r < vl || vl > vr) return 0;
  if (l <= vl && vr <= r)
    return lower_bound(t[v].begin(), t[v].end(), k) - t[v].begin();
  return query(v * 2, l, r, vl, (vl + vr) / 2, k) +
         query(v * 2 + 1, l, r, (vl + vr) / 2 + 1, vr, k);
}
int32_t main() {
  int n, m, uu = 1;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<int> u(n);
  for (int i = 0; i < n; i++)
    cin >> a[i].first, a[i].second = -i, u[i] = a[i].first;
  while (uu < n) uu <<= 1;
  n = uu;
  while (a.size() < n) a.push_back({-1e9, -(int)a.size()}), u.push_back(1e9);
  t.resize(n * 2);
  vector<int> z(n + 1);
  sort(a.rbegin(), a.rend());
  for (int i = 0; i < n; i++) z[i] = -a[i].second, t[i + n].push_back(z[i]);
  for (int i = n - 1; i > 0; i--) {
    t[i].reserve(t[i * 2].size());
    for (auto e : t[i * 2]) t[i].push_back(e);
    for (auto e : t[i * 2 + 1]) t[i].push_back(e);
    sort(t[i].begin(), t[i].end());
  }
  cin >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    int l = 0, r = n + 1;
    while (l < r - 1) {
      int m = (l + r) / 2;
      int ans = query(1, 0, a - 1, 0, n - 1, m);
      if (ans > b - 1)
        r = m;
      else
        l = m;
    }
    cout << u[l] << "\n";
  }
}
