#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void pv(vector<T> v) {
  for (T x : v) cout << x << " ";
  cout << "\n";
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
const int N = 1e9 + 7;
const int mod = 998244353;
vector<int> BIT(200005, 0), ans, b;
vector<pair<int, int>> a;
vector<pair<pair<int, int>, int>> q;
void add(int i, int x) {
  for (; i < BIT.size(); i += i & (-i)) BIT[i] += x;
}
int get(int i) {
  int sum = 0;
  for (; i > 0; i -= i & (-i)) sum += BIT[i];
  return sum;
}
int bit_search(long long val) {
  long long sum = 0, pos = 0;
  for (int i = log2(BIT.size()); i >= 0; i--)
    if (pos + (1 << i) < BIT.size() && sum + BIT[pos + (1 << i)] < val)
      sum += BIT[pos + (1 << i)], pos += (1 << i);
  return pos + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n = read(), k, pos, m;
  b.push_back(N);
  for (int i = 0; i < (n); i++) b.push_back(read());
  for (int i = 0; i < (n + 1); i++) a.push_back(make_pair(-b[i], i));
  m = read();
  for (int i = 0; i < (m); i++) {
    k = read(), pos = read();
    q.push_back(make_pair(make_pair(k, pos), i));
  }
  sort((a).begin(), (a).end());
  sort((q).begin(), (q).end());
  int ind = 1;
  ans.resize(m, -1);
  for (int i = 0; i < (m); i++) {
    while (q[i].first.first >= ind) add(a[ind].second, 1), ind++;
    ans[q[i].second] = b[bit_search(q[i].first.second)];
  }
  for (int x : ans) cout << x << "\n";
  return 0;
}
