#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, q;
int niz[maxn];
pair<int, int> pom[maxn];
int res[maxn];
vector<pair<int, int> > vec[maxn];
bool cmp(pair<int, int> s1, pair<int, int> s2) {
  if (s1.first == s2.first) return s1.second < s2.second;
  return s1.first > s2.first;
}
long long dud[maxn];
void upd(int x, long long val) {
  while (x <= maxn) {
    dud[x] += val;
    x += x & (-x);
  }
}
long long query(int x) {
  long long sum = 0;
  while (x > 0) {
    sum += dud[x];
    x -= x & (-x);
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> niz[i];
    pom[i] = {niz[i], i};
  }
  sort(pom + 1, pom + n + 1, cmp);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back({b, i});
  }
  for (int i = 1; i <= n; i++) {
    int poz = pom[i].second;
    upd(poz, 1);
    for (auto c : vec[i]) {
      int x = c.first;
      int ind = c.second;
      int l = 1, r = n, ans = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        if (query(mid) >= x) {
          r = mid - 1;
          ans = mid;
        } else
          l = mid + 1;
      }
      res[ind] = niz[ans];
    }
  }
  for (int i = 1; i <= q; i++) cout << res[i] << endl;
  return 0;
}
