#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
int BIT[N];
const int p = log2(N) + 3;
void update(int x, int val) {
  while (x < N) {
    BIT[x] += val;
    x += (x & (-x));
  }
}
int query(int k) {
  int ans = 0, sum = 0, i;
  for (i = p; i >= 0; --i) {
    ans += 1 << i;
    if ((ans < N) && ((sum + BIT[ans]) < k)) {
      sum += BIT[ans];
    } else
      ans -= 1 << i;
  }
  return (ans + 1);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, i, q, k, pos, j;
  cin >> n;
  int arr[n + 1];
  pair<int, int> b[n + 1];
  for (i = 1; i <= n; ++i) {
    cin >> b[i].first;
    b[i].second = -i;
    arr[i] = b[i].first;
  }
  sort(b + 1, b + n + 1);
  cin >> q;
  int ans[q + 1];
  vector<pair<int, int>> a[n + 1];
  for (i = 1; i <= q; ++i) {
    cin >> k >> pos;
    a[k].push_back({pos, i});
  }
  for (i = 1; i <= n; ++i) {
    update(-1 * b[n - i + 1].second, 1);
    for (j = 0; j < a[i].size(); ++j) {
      int v = ans[a[i][j].second] = arr[query(a[i][j].first)];
    }
  }
  for (i = 1; i <= q; ++i) cout << ans[i] << "\n";
  return 0;
}
