#include <bits/stdc++.h>
using namespace std;
template <typename Type = int>
struct BIT {
  int bit_size;
  vector<Type> data;
  BIT(int n) {
    bit_size = n;
    data.assign(n + 2, 0);
  }
  void add(int k, Type x) {
    k++;
    while (k <= bit_size) {
      data[k] += x;
      k += k & (-k);
    }
  }
  Type query(int k) {
    Type rec = 0;
    while (k > 0) {
      rec += data[k];
      k -= k & (-k);
    }
    return rec;
  }
  Type query(int a, int b) { return query(b) - query(a); }
};
int N, M, A[200010], ans[200010];
pair<pair<int, int>, int> query[200010];
int main() {
  scanf("%d", &N);
  using piii = pair<pair<int, int>, int>;
  priority_queue<piii> pq;
  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
    pq.push({{A[i], -i}, 0});
  }
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    int pos, k;
    scanf("%d%d", &k, &pos);
    query[i] = {{k, pos}, i};
  }
  sort(query, query + M);
  BIT<int> bit(N);
  int curlen = 0;
  for (int i = 0; i < M; i++) {
    int len = query[i].first.first;
    int pos = query[i].first.second;
    int idx = query[i].second;
    while (len > curlen) {
      auto p = pq.top();
      pq.pop();
      bit.add(-p.first.second, 1);
      curlen++;
    }
    int l = 0, r = N - 1;
    while (l < r) {
      int mid = (l + r) / 2;
      if (pos <= bit.query(mid + 1)) {
        r = mid;
      } else {
        l = mid + 1;
      }
    }
    ans[idx] = A[l];
  }
  for (int i = 0; i < M; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
