#include <bits/stdc++.h>
using namespace std;
void solve() {}
const long long maxn = 200500;
long long a[maxn];
long long seg[3 * maxn];
long long n;
void upd(long long pos, long long val) {
  pos += 2e5;
  seg[pos] = val;
  for (long long i = pos / 2; i >= 1; i /= 2) {
    seg[i] = seg[i * 2] + seg[i * 2 + 1];
  }
}
long long query(long long l, long long r) {
  l += 2e5, r += 2e5;
  long long res = 0;
  while (l <= r) {
    if (l % 2 == 1) res += seg[l++];
    if (r % 2 == 0) res += seg[r--];
    l /= 2;
    r /= 2;
  }
  return res;
}
set<long long> S;
map<long long, long long> cmp, rcmp;
long long curc = 1;
bool comp(pair<long long, long long> &l, pair<long long, long long> &r) {
  if (l.first == r.first) {
    return l.second < r.second;
  }
  return l.first > r.first;
}
struct Query {
  long long k, pos, ind;
  Query(long long kk, long long poss, long long indd) {
    k = kk;
    pos = poss;
    ind = indd;
  }
};
bool compQuery(Query &l, Query &r) { return l.k < r.k; }
vector<Query> queries;
long long ans[maxn];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > vals;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    vals.emplace_back(a[i], i);
    S.emplace(a[i]);
  }
  for (long long x : S) {
    cmp[x] = curc;
    rcmp[curc] = x;
    curc++;
  }
  for (long long i = 0; i < (long long)vals.size(); i++) {
    vals[i].first = cmp[vals[i].first];
  }
  sort((vals).begin(), (vals).end(), comp);
  long long m;
  cin >> m;
  for (long long i = 1; i <= m; i++) {
    long long k, pos;
    cin >> k >> pos;
    queries.emplace_back(k, pos, i);
  }
  sort((queries).begin(), (queries).end(), compQuery);
  long long cur = 0;
  for (Query q : queries) {
    while (cur < q.k) {
      long long pre = query(vals[cur].second, vals[cur].second);
      upd(vals[cur].second, pre + 1);
      cur++;
    }
    long long l = 1;
    long long r = 2e5;
    long long lgood = -1;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (query(1, mid) >= q.pos) {
        lgood = mid;
        r = mid - 1;
      } else {
        l = mid + 1;
      }
    }
    ans[q.ind] = a[lgood];
    if (false) cerr << '\n';
  }
  for (long long i = 1; i <= m; i++) {
    cout << ans[i] << '\n';
  }
}
