#include <bits/stdc++.h>
using namespace std;
void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int cnt[512];
int val[200016];
int ans[200016];
pair<int, int> a[200016];
vector<pair<int, int> > wh[200016];
int main() {
  canhazfast();
  int n, q, r = 1;
  cin >> n;
  while (r * r <= n) ++r;
  --r;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = -i;
  }
  sort(a, a + n, greater<pair<int, int> >());
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int len, pos;
    cin >> len >> pos;
    wh[len - 1].emplace_back(pos, i);
  }
  for (int i = 0; i < n; ++i) {
    int id = -a[i].second;
    ++cnt[id / r];
    val[id] = a[i].first;
    for (const pair<int, int> &x : wh[i]) {
      int pos = x.first, cur = 0;
      while (pos > cnt[cur]) {
        pos -= cnt[cur];
        ++cur;
      }
      for (int j = cur * r; j < cur * r + r; ++j) {
        if (val[j] && !--pos) {
          ans[x.second] = val[j];
          break;
        }
      }
    }
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
  return 0;
}
