#include <bits/stdc++.h>
using namespace std;
int n, m;
int t[200001];
int ans[200001];
int er[200001];
vector<pair<int, int> > sz;
vector<pair<int, int> > q[200001];
int ask(int a) {
  int sum = 0;
  while (a > 0) {
    sum += t[a];
    a -= ((a) & -(a));
  }
  return sum;
}
void add(int a) {
  while (a <= 200000) {
    t[a]++;
    a += ((a) & -(a));
  }
}
int solve(int a) {
  int x = 0, y = n;
  while (y - x > 1) {
    int z = (x + y) / 2;
    int p = ask(z);
    if (p >= a) {
      y = z;
    } else {
      x = z;
    }
  }
  return y;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> er[i];
    sz.push_back({-er[i], i});
  }
  sort(sz.begin(), sz.end());
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    q[a].push_back({b, i});
  }
  for (int i = 1; i <= n; i++) {
    add(sz[i - 1].second);
    for (int j = 0; j < q[i].size(); j++) {
      int fi = q[i][j].first;
      int x = solve(fi);
      ans[q[i][j].second] = er[x];
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
