#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int a[MAXN];
int n;
struct segtree {
  vector<int> t;
  segtree() { t.resize(4 * MAXN); }
  void upd(int i, int l, int r, int qi) {
    if (l == r) {
      t[i] = 1;
      return;
    }
    int m = (l + r) >> 1;
    if (qi <= m) {
      upd(i * 2 + 1, l, m, qi);
    } else {
      upd(i * 2 + 2, m + 1, r, qi);
    }
    t[i] = t[i * 2 + 1] + t[i * 2 + 2];
  }
  int get(int i, int l, int r, int qi) {
    if (l == r) return a[l];
    int m = (l + r) >> 1;
    if (qi <= t[i * 2 + 1]) return get(i * 2 + 1, l, m, qi);
    return get(i * 2 + 2, m + 1, r, qi - t[i * 2 + 1]);
  }
};
struct qqq {
  int k, j, ind;
  qqq(int k, int j, int ind) : k(k), j(j), ind(ind) {}
};
bool cmp(pair<int, int> &a, pair<int, int> &b) {
  return (a.first == b.first) ? (a.second < b.second) : (a.first > b.first);
}
bool cmp1(qqq &a, qqq &b) { return (a.k < b.k); }
signed main() {
  cin >> n;
  segtree st1;
  vector<pair<int, int> > b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
  }
  sort(b.begin(), b.end(), cmp);
  int q;
  cin >> q;
  vector<qqq> q1;
  vector<int> ans(q);
  for (int i = 0; i < q; i++) {
    int k, j;
    cin >> k >> j;
    q1.push_back(qqq(k, j, i));
  }
  sort(q1.begin(), q1.end(), cmp1);
  int j = 0;
  for (int i = 0; i < q; i++) {
    while (j < q1[i].k) {
      st1.upd(0, 0, n - 1, b[j].second);
      j++;
    }
    ans[q1[i].ind] = st1.get(0, 0, n - 1, q1[i].j);
  }
  for (int x : ans) {
    cout << x << '\n';
  }
  return 0;
}
