#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5 + 5;
int sum[4 * NMAX + 5];
int v[NMAX + 5];
int ordine[NMAX + 5];
int N, Q;
vector<int> queries[NMAX + 5];
unordered_map<int, int> answers[NMAX + 5];
vector<pair<int, int>> qq;
void update(int nod, int st, int dr, int poz) {
  if (poz < st || dr < poz) return;
  if (st == dr) {
    sum[nod] = 1;
    return;
  }
  update((2 * nod), st, ((st + dr) / 2), poz);
  update((2 * nod + 1), ((st + dr) / 2) + 1, dr, poz);
  sum[nod] = sum[(2 * nod)] + sum[(2 * nod + 1)];
}
int query(int nod, int st, int dr, int poz) {
  if (st == dr) return v[st];
  if (poz <= sum[(2 * nod)]) return query((2 * nod), st, ((st + dr) / 2), poz);
  return query((2 * nod + 1), ((st + dr) / 2) + 1, dr, poz - sum[(2 * nod)]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> v[i];
    ordine[i] = i;
  }
  sort(ordine + 1, ordine + N + 1, [&](int a, int b) {
    if (v[a] != v[b]) return v[a] > v[b];
    return a < b;
  });
  cin >> Q;
  for (int i = 1; i <= Q; ++i) {
    int lg, poz;
    cin >> lg >> poz;
    queries[lg].push_back(poz);
    qq.push_back({lg, poz});
  }
  for (int lg = 1; lg <= N; ++lg) {
    update(1, 1, N, ordine[lg]);
    auto vec = queries[lg];
    sort(vec.begin(), vec.end());
    for (auto x : vec) {
      answers[lg][x] = query(1, 1, N, x);
    }
  }
  for (auto pp : qq) {
    cout << answers[pp.first][pp.second] << '\n';
  }
  return 0;
}
