#include <bits/stdc++.h>
using namespace std;
template <class Monoid>
struct SegmentTree {
  using Function = function<Monoid(Monoid, Monoid)>;
  int N;
  vector<Monoid> segment;
  const Function func;
  const Monoid id;
  SegmentTree(int n, const Function func, const Monoid id)
      : func(func), id(id) {
    N = 1;
    while (N < n) N <<= 1;
    segment.assign(2 * N, id);
  }
  void set(int num, Monoid x) { segment[N + num] = x; }
  void build() {
    for (int k = N - 1; k > 0; k--) {
      segment[k] = func(segment[2 * k], segment[2 * k + 1]);
    }
  }
  void update(int k, Monoid x) {
    k = k + N;
    segment[k] = x;
    while (k >>= 1) {
      segment[k] = func(segment[2 * k], segment[2 * k + 1]);
    }
  }
  Monoid query(int a, int b) {
    Monoid L = id;
    Monoid R = id;
    a += N;
    b += N;
    for (; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = func(L, segment[a++]);
      if (b & 1) R = func(segment[--b], R);
    }
    return func(L, R);
  }
  Monoid operator[](const int k) const { return segment[N + k]; }
};
struct dat {
  long long val;
  int idx;
};
struct dat dat_merge(struct dat a, struct dat b) {
  if (a.val > b.val || (a.val == b.val && a.idx < b.idx))
    return a;
  else
    return b;
}
template <class T>
struct Fenwick {
  vector<T> bit;
  int N;
  Fenwick(int n) {
    N = n;
    bit.resize(n + 1, 0);
  }
  void add(int a, T w) {
    for (int x = a; x <= N; x += x & -x) bit[x] += w;
  }
  T sum(int a) {
    T ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
  int get(int a) {
    int l = 0, r = N;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (sum(mid) >= a)
        r = mid;
      else
        l = mid;
    }
    return r;
  }
};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  struct dat dat_id = {-1LL, (int)1e9};
  vector<long long> x(n);
  SegmentTree<struct dat> st(n, dat_merge, dat_id);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    st.set(i, {x[i], i});
  }
  st.build();
  int m;
  cin >> m;
  deque<pair<pair<int, int>, int>> q;
  vector<long long> ans(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    q.push_back({{a, b}, i});
  }
  sort(q.begin(), q.end());
  Fenwick<int> f(n);
  for (int i = 1; i <= n; i++) {
    auto u = st.query(0, n);
    st.update(u.idx, dat_id);
    f.add(u.idx + 1, 1);
    while (!q.empty() && q.begin()->first.first == i) {
      auto p = q.front();
      q.pop_front();
      ans[p.second] = x[f.get(p.first.second) - 1];
    }
  }
  for (int i = 0; i < m; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
