#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long ml = kk * kk;
const long long mod = ml * kk + 7;
const long long inf = ml * ml * ml + 7;
long long n, i, j;
vector<pair<long long, long long>> m;
vector<long long> p, rm;
vector<pair<pair<long long, long long>, long long>> qr;
long long done;
vector<long long> ans;
bool viv = false;
vector<long long> t;
long long s;
void show() {
  for (long long i = 1; i < 2 * s; i++) {
    cout << t[i] << ' ';
    if (!((i) & (i + 1))) cout << endl;
  }
  cout << "____ " << endl;
}
void build() {
  s = 1;
  while (s < n + 1) s <<= 1;
  t.resize(2 * s);
}
void prepare() {
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    qr.push_back({{a, b}, i});
  }
  sort(qr.begin(), qr.end());
  ans.resize(q, -1);
  build();
}
void add(long long pl) {
  pl += s;
  while (pl) {
    t[pl]++;
    pl >>= 1;
  }
}
long long find(long long v, long long l, long long r, long long k) {
  if (l == r) return r;
  long long mi = l + r >> 1;
  if (viv)
    cout << "I'm on " << v << " [" << l << "; " << r << "] and " << t[2 * v]
         << endl;
  if (t[2 * v] < k) return find(2 * v + 1, mi + 1, r, k - t[2 * v]);
  return find(2 * v, l, mi, k);
}
long long get(long long k) {
  if (viv) cout << "Hmmm " << find(1, 0, s - 1, k) << endl;
  return find(1, 0, s - 1, k);
}
void solve(pair<pair<long long, long long>, long long> z) {
  while (done < z.first.first) {
    add(p[done]);
    done++;
  }
  if (viv) {
    cout << "done " << done << endl;
    show();
  }
  long long res = get(z.first.second);
  if (viv) cout << "Here get the ans on " << res << endl;
  ans[z.second] = rm[res];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) {
    long long a;
    cin >> a;
    rm.push_back(a);
    m.push_back({a, -i});
  }
  sort(m.rbegin(), m.rend());
  for (auto i : m) p.push_back(-i.second);
  prepare();
  for (auto i : qr) solve(i);
  for (auto i : ans) cout << i << '\n';
  return 0;
}
