#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); }
const int maxn = 2e5 + 10;
pair<int, int> p[maxn];
bool cmp(pair<int, int> f, pair<int, int> s) {
  if (f.first != s.first) return f.first > s.first;
  return f.second < s.second;
}
vector<pair<int, int> > qu[maxn];
int answer[maxn], a[maxn], fen[maxn];
void add(int p, int val) {
  for (p++; p < maxn; p += p & -p) fen[p] += val;
}
int get(int p) {
  int res = 0;
  for (p++; p; p -= p & -p) res += fen[p];
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = x;
    p[i] = {x, i};
  }
  sort(p, p + n, cmp);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k, pos;
    cin >> k >> pos;
    qu[k].push_back({pos, i});
  }
  for (int i = 1; i <= n; i++) {
    int ind = p[i - 1].second;
    add(ind, 1);
    for (auto t : qu[i]) {
      int pos = t.first, id = t.second;
      int lo = -1, hi = n + 1;
      while (hi - lo > 1) {
        int mid = hi + lo >> 1;
        if (get(mid) >= pos)
          hi = mid;
        else
          lo = mid;
      }
      answer[id] = hi;
    }
  }
  for (int i = 0; i < q; i++) cout << a[answer[i]] << '\n';
}
