#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vii = vector<int>;
ll low(ll x) { return (x & -x); }
ll n;
const ll N = 2e5 + 10;
ll a[N], id[N];
ll lc[N * 40], rc[N * 40], val[N * 40];
ll rt[N];
ll cnt = 0;
void upd(ll pre, ll& p, ll l, ll r, ll v) {
  p = ++cnt;
  val[p] = val[pre] + 1;
  lc[p] = lc[pre];
  rc[p] = rc[pre];
  if (l == r) {
    return;
  }
  ll mid = l + r >> 1;
  if (v <= mid)
    upd(lc[pre], lc[p], l, mid, v);
  else
    upd(rc[pre], rc[p], mid + 1, r, v);
}
ll find(ll l, ll r, ll p, ll k) {
  if (l == r) return l;
  ll mid = l + r >> 1;
  ll sz = val[lc[p]];
  if (sz >= k)
    return find(l, mid, lc[p], k);
  else
    return find(mid + 1, r, rc[p], k - sz);
}
signed main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (ll i = 1; i <= n; i++) cin >> a[i], id[i] = i;
  sort(id + 1, id + n + 1,
       [](ll x, ll y) { return a[x] > a[y] || (a[x] == a[y] && x < y); });
  for (ll i = 1; i <= n; i++) {
    upd(rt[i - 1], rt[i], 1, n, id[i]);
  }
  ll m;
  cin >> m;
  while (m--) {
    ll k, pos;
    cin >> k >> pos;
    cout << a[find(1, n, rt[k], pos)] << '\n';
  }
  return 0;
}
