#include <bits/stdc++.h>
using namespace std;
const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;
template <typename T>
void read(vector<T>& a) {
  for (auto& v : a) cin >> v;
}
int w;
struct tree {
  vector<long long> t;
  int n;
  tree(vector<int>& a) {
    n = a.size();
    w = 1 << (32 - __builtin_clz(n));
    t.resize((w << 1));
    for (int i = w; i < w + n; i++) t[i] = a[i - w];
    for (int i = w - 1; i > 0; i--) t[i] = t[2 * i] + t[2 * i + 1];
  }
  void set(int i) {
    i += w;
    t[i] = 1;
    i >>= 1;
    while (i) {
      t[i] = t[2 * i] + t[2 * i + 1];
      i >>= 1;
    }
  }
  int search(int x, int v = 1, int lx = 0, int rx = w - 1) {
    int m = (lx + rx) >> 1;
    if (lx == rx) return rx;
    if (t[2 * v] >= x) {
      return search(x, 2 * v, lx, m);
    }
    return search(x - t[2 * v], 2 * v + 1, m + 1, rx);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  int n;
  cin >> n;
  vector<int> arr(n);
  read(arr);
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = {arr[i], i};
  }
  sort(a.begin(), a.end(), [](pair<int, int> a, pair<int, int> b) {
    return a.first == b.first ? a.second < b.second : a > b;
  });
  int m;
  cin >> m;
  vector<vector<int>> q(m, vector<int>(3));
  vector<int> ans(m);
  for (int i = 0; i < m; i++) {
    cin >> q[i][0] >> q[i][1];
    q[i][2] = i;
  }
  sort(q.begin(), q.end());
  vector<int> tr(n);
  tree t(tr);
  int sz = 0;
  for (auto& p : q) {
    while (sz < p[0]) {
      t.set(a[sz++].second);
    }
    ans[p[2]] = arr[t.search(p[1])];
  }
  for (auto& v : ans) cout << v << '\n';
}
