#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class Abel>
struct BIT {
 private:
  vector<Abel> node;
  long long n;
  Abel UNITY_SUM = 0;

 public:
  BIT(long long n_) {
    n = n_;
    node.resize(n, UNITY_SUM);
  }
  void add(long long a, Abel w) {
    for (long long i = a; i < n; i |= i + 1) node[i] += w;
  }
  Abel sum(long long a) {
    Abel ret = UNITY_SUM;
    for (long long i = a - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i];
    return ret;
  }
  Abel sum(long long a, long long b) { return sum(b) - sum(a); }
  long long get(long long k) {
    ++k;
    long long res = 0;
    long long n = 1;
    while (n < (long long)node.size()) n *= 2;
    for (long long i = n / 2; i > 0; i /= 2) {
      if (res + i <= (long long)node.size() && node[res + i - 1] < k) {
        k -= node[res + i - 1];
        res += i;
      }
    }
    return res;
  }
  void print() {
    for (long long i = 0; i < n; ++i) cout << sum(i, i + 1) << ",";
    cout << endl;
  }
};
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long m;
  cin >> m;
  vector<long long> ans(m);
  vector<vector<pair<long long, long long>>> g(
      n + 1, vector<pair<long long, long long>>());
  for (long long i = 0; i < m; i++) {
    long long k, pos;
    cin >> k >> pos;
    --pos;
    g[k].push_back({i, pos});
  }
  vector<pair<long long, long long>> x(n);
  for (long long i = 0; i < n; i++) x[i] = {a[i], -i};
  sort(x.begin(), x.end());
  reverse(x.begin(), x.end());
  BIT<long long> ids(n);
  for (long long k = 0; k < n; k++) {
    ids.add(-x[k].second, 1);
    for (auto p : g[k + 1]) {
      long long j = p.first, pos = p.second;
      ans[j] = a[ids.get(pos)];
    }
  }
  for (long long i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
