#include <bits/stdc++.h>
using namespace std;
const int N = 500023;
long long int vis[N] = {0};
vector<long long int> adj[N];
long long int count1[N] = {0};
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.first > b.first)
    return 1;
  else if (a.first == b.first)
    return (a.second < b.second);
  else
    return 0;
}
long long int query(long long int l, long long int r, long long int pos,
                    long long int k) {
  if (count1[pos] < k) return -1;
  if (l == r) return l;
  long long int mid = (l + r) / 2;
  if (count1[2 * pos + 1] >= k)
    return query(l, mid, 2 * pos + 1, k);
  else
    return query(mid + 1, r, 2 * pos + 2, k - count1[2 * pos + 1]);
}
void update(long long int l, long long int r, long long int val,
            long long int pos) {
  if (val < l || val > r) return;
  if (l == r) {
    count1[pos] = 1;
    return;
  }
  long long int mid = (l + r) / 2;
  if (val <= mid)
    update(l, mid, val, 2 * pos + 1);
  else
    update(mid + 1, r, val, 2 * pos + 2);
  count1[pos] = count1[2 * pos + 1] + count1[2 * pos + 2];
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int>> v;
  vector<long long int> copy;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    v.push_back({x, i + 1});
    copy.push_back(x);
  }
  sort((v).begin(), (v).end(), sortbysec);
  long long int m;
  cin >> m;
  vector<pair<long long int, long long int>> q;
  map<pair<long long int, long long int>, long long int> ans;
  vector<pair<long long int, long long int>> order;
  for (long long int i = 0; i < m; i++) {
    long long int k, pos;
    cin >> k >> pos;
    q.push_back({k, pos});
    order.push_back({k, pos});
  }
  sort((q).begin(), (q).end());
  long long int curr = 0;
  for (long long int i = 0; i < m; i++) {
    for (long long int j = curr; j < q[i].first; j++)
      update(0, n + 1, v[j].second, 0);
    curr = q[i].first;
    ans[{q[i].first, q[i].second}] = query(0, n + 1, 0, q[i].second);
  }
  for (long long int i = 0; i < m; i++) cout << copy[ans[order[i]] - 1] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  T = 1;
  long long int t = 0;
  while (t++ < T) {
    solve();
    cout << '\n';
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
