#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
int a[N], b[N];
int fen[N];
vector<int> ind[N];
int ans[N];
vector<pair<int, int>> qu[N];
void add(int x) {
  for (; x < N; x += x & -x) fen[x]++;
}
int get(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += fen[x];
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> vx;
  for (int i = 0; i < n; i++) cin >> a[i], vx.push_back(a[i]);
  sort(vx.begin(), vx.end());
  vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
  for (int i = 0; i < n; i++)
    b[i] = lower_bound(vx.begin(), vx.end(), a[i]) - vx.begin();
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    qu[x].push_back({y, i});
  }
  vector<int> all;
  for (int i = 0; i < n; i++) ind[b[i]].push_back(i);
  for (int i = n - 1; i > -1; i--)
    for (auto u : ind[i]) all.push_back(u + 1);
  for (int i = 1; i <= n; i++) {
    add(all[i - 1]);
    for (auto u : qu[i]) {
      int x = u.first;
      int id = u.second;
      int l = 0, r = n + 1;
      while (r - l > 1) {
        int mid = (l + r) / 2;
        if (get(mid) < x)
          l = mid;
        else
          r = mid;
      }
      ans[id] = r;
    }
  }
  for (int i = 0; i < q; i++) cout << a[ans[i] - 1] << '\n';
}
