#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const int maxn = 1e6 + 7;
vector<int> d(maxn);
int n;
void add(int x) {
  for (int i = x; i <= n; i += i & -i) ++d[i];
}
int query(int x) {
  if (x == 0) return 0;
  int ret = 0;
  for (int i = x; i > 0; i -= i & -i) ret += d[i];
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  vector<int> a(n + 1);
  vector<pair<int, int> > b(n + 1);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i + 1];
    b[i + 1] = pair<int, int>(-a[i + 1], i + 1);
  }
  sort(b.begin(), b.end());
  int m;
  cin >> m;
  vector<pair<pair<int, int>, int> > req(m + 1);
  for (int i = 0; i < (m); ++i) {
    cin >> req[i + 1].first.first >> req[i + 1].first.second;
    req[i + 1].second = i + 1;
  }
  sort(req.begin(), req.end());
  vector<int> ans(m + 1);
  int len = 0;
  for (int i = 0; i < (m); ++i) {
    while (len < req[i + 1].first.first) {
      add(b[len].second);
      ++len;
    }
    int l = 0, r = n;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      if (query(mid) >= req[i + 1].first.second)
        r = mid;
      else
        l = mid;
    }
    ans[req[i + 1].second] = a[r];
  }
  for (int i = 0; i < (m); ++i) cout << ans[i + 1] << endl;
}
