#include <bits/stdc++.h>
using namespace std;
int seg[(int)(2e5 + 1) * 4];
void update(int s, int e, int idx, int k) {
  if (s == e && s == k) {
    seg[idx] = 1;
    return;
  }
  if (s > k || e < k) return;
  int mid = (s + e) / 2;
  update(s, mid, idx * 2, k);
  update(mid + 1, e, idx * 2 + 1, k);
  seg[idx] = seg[idx * 2] + seg[idx * 2 + 1];
}
int kth(int s, int e, int idx, int k) {
  if (s == e) return s;
  int mid = (s + e) / 2;
  if (seg[idx * 2] >= k)
    return kth(s, mid, idx * 2, k);
  else
    return kth(mid + 1, e, idx * 2 + 1, k - seg[idx * 2]);
}
void look(int s, int e, int idx) {
  if (s == e) {
    return;
  }
  int mid = (s + e) / 2;
  look(s, mid, idx * 2);
  look(mid + 1, e, idx * 2 + 1);
}
struct ano {
  int k;
  int pos;
  int id;
};
bool cmp(ano a, ano b) {
  if (a.k == b.k) return a.pos < b.pos;
  return a.k < b.k;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int i;
  int arr[n];
  pair<int, int> sorted[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    sorted[i].first = -arr[i];
    sorted[i].second = i;
  }
  sort(sorted, sorted + n);
  int q;
  cin >> q;
  ano ask[q];
  for (i = 0; i < q; i++) {
    cin >> ask[i].k >> ask[i].pos;
    ask[i].id = i;
  }
  sort(ask, ask + q, cmp);
  int ans[q];
  int curr = -1;
  for (i = 0; i < q; i++) {
    while (curr < ask[i].k - 1) {
      curr++;
      update(0, n - 1, 1, sorted[curr].second);
    }
    int pos = kth(0, n - 1, 1, ask[i].pos);
    ans[ask[i].id] = arr[pos];
  }
  for (i = 0; i < q; i++) cout << ans[i] << '\n';
}
