#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e18;
mt19937 Flash_new_51(51515);
using vi = vector<long long>;
using vp = vector<pair<long long, long long>>;
struct Node {
  long long k, pos, ind;
  Node() { k = pos = ind = 0; }
  Node(long long k1, long long pos1, long long ind1) {
    k = k1, pos = pos1, ind = ind1;
  }
};
vector<Node> kek;
bool cmp(Node A, Node B) {
  if (A.k == B.k) {
    return A.pos < B.pos;
  }
  return A.k < B.k;
}
long long t[N], n, ans[N], b[N];
pair<long long, long long> a[N];
bool used[N];
void inc(long long i, long long delta) {
  used[i] = 1;
  for (; i < n; i |= (i + 1)) {
    t[i] += delta;
  }
}
long long sum(long long i) {
  long long summ = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) summ += t[i];
  return summ;
}
long long zap(long long pos) {
  long long l = 0, r = n;
  while (r - l > 1) {
    long long m = (r + l) >> 1;
    long long k = sum(m);
    if (k == pos) {
      if (used[m])
        return b[m];
      else
        r = m;
    } else {
      if (k < pos)
        l = m;
      else
        r = m;
    }
  }
  return b[l];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = -i;
    b[i] = a[i].first;
  }
  sort(a, a + n);
  reverse(a, a + n);
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long k, pos;
    cin >> k >> pos;
    kek.push_back({k, pos, i});
  }
  sort(kek.begin(), kek.end(), cmp);
  long long tek = 0;
  for (auto to : kek) {
    for (long long i = tek; i < to.k; i++) {
      inc(abs(a[i].second), 1);
    }
    tek = to.k;
    ans[to.ind] = zap(to.pos);
  }
  for (long long i = 0; i < q; i++) cout << ans[i] << "\n";
}
