#include <bits/stdc++.h>
using namespace std;
struct fenwickTree {
  vector<long long> bit;
  long long n;
  fenwickTree() {
    n = (long long)2e5 + 3;
    bit.assign(n, 0);
  }
  long long sum(long long r) {
    long long ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  void add(long long idx, long long d) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += d;
  }
  long long sum(long long l, long long r) { return sum(r) - sum(l - 1); }
} ft;
struct query {
  long long len, pos, i;
};
const long long N = 2e5 + 5;
long long arr[N];
pair<long long, long long> sorted[N];
query queries[N];
long long res[N];
bool cmp(const query &x, const query &y) { return x.len < y.len; }
bool cmpsort(const pair<long long, long long> &x,
             const pair<long long, long long> &y) {
  return x.first > y.first;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, vector<long long>> index;
  for (long long i = 0; i < n; ++i) {
    cin >> arr[i];
    sorted[i] = {arr[i], i};
    index[arr[i]].push_back(i);
  }
  sort(sorted, sorted + n, cmpsort);
  long long m;
  cin >> m;
  for (long long i = 0; i < m; ++i) {
    cin >> queries[i].len >> queries[i].pos;
    queries[i].i = i;
  }
  sort(queries, queries + m, cmp);
  long long posSort = 0;
  for (long long i = 0; i < m; ++i) {
    const long long len = queries[i].len;
    const long long pos = queries[i].pos;
    const long long id = queries[i].i;
    const long long currVal = sorted[len - 1].first;
    while (posSort < n && sorted[posSort].first > currVal) {
      ft.add(sorted[posSort].second, 1);
      ++posSort;
    }
    long long start = -1, end = n - 1, mid;
    while (start + 1 < end) {
      mid = (start + end) / 2;
      long long howMany = ft.sum(0, mid);
      auto &v = index[currVal];
      long long temp = (upper_bound(v.begin(), v.end(), mid) - v.begin());
      temp = min(temp, len - posSort);
      howMany += temp;
      if (howMany >= pos) {
        end = mid;
      } else
        start = mid;
    }
    res[id] = arr[end];
  }
  for (long long i = 0; i < m; ++i) {
    cout << res[i] << '\n';
  }
}
