#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 100, OO = 1e6 + 1000, M = 1e9 + 7, P = 6151,
                SQ = 1000, lg = 30;
vector<pair<long long, long long> > v[N];
long long cnt[N];
pair<long long, long long> a[N];
struct node {
  long long num = 0, ans = 0;
} seg[N << 2];
void upd(long long c, long long b, long long e, long long l, long long r) {
  if (e - b == 1) {
    seg[c].ans = r;
    seg[c].num = 1;
    return;
  }
  long long mid = (b + e) >> 1;
  if (l < mid)
    upd(c << 1, b, mid, l, r);
  else
    upd(c << 1 | 1, mid, e, l, r);
  seg[c].num = seg[c << 1].num + seg[c << 1 | 1].num;
}
long long get(long long c, long long b, long long e, long long l) {
  if (e - b == 1) return seg[c].ans;
  long long mid = (b + e) >> 1;
  if (seg[c << 1].num >= l)
    return get(c << 1, b, mid, l);
  else
    return get(c << 1 | 1, mid, e, l - seg[c << 1].num);
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = -1 * i;
  }
  sort(a, a + n);
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back({y, i});
  }
  for (long long i = n - 1; i >= 0; i--) {
    long long j = n - i;
    upd(1, 0, n, a[i].second * -1, a[i].first);
    for (auto u : v[j]) cnt[u.second] = get(1, 0, n, u.first);
  }
  for (long long i = 0; i < m; i++) cout << cnt[i] << endl;
  return 0;
}
