#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
using namespace std;
const long long INF = 1e18;
const int int_INF = 1e9 + 13;
const long double PI = acos(-1);
const long double EPS = 1e-9;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 13;
vector<int> tree(4 * MAXN);
vector<int> arr(MAXN);
void build(int cur, int l, int r) {
  if (l == r - 1)
    tree[cur] = 0;
  else if (l >= r)
    return;
  else {
    long long m = (l + r) / 2;
    build(2 * cur + 1, l, m);
    build(2 * cur + 2, m, r);
    tree[cur] = tree[2 * cur + 1] + tree[2 * cur + 2];
  }
}
void add(int cur, int l, int r, int x, int pos) {
  if (l >= r || l > pos || pos >= r)
    return;
  else if (l == r - 1)
    tree[cur] += x;
  else {
    long long m = (l + r) / 2;
    add(2 * cur + 1, l, m, x, pos);
    add(2 * cur + 2, m, r, x, pos);
    tree[cur] += x;
  }
}
int with_sum(int cur, int l, int r, int k) {
  if (l == r - 1)
    return l;
  else if (tree[2 * cur + 1] >= k)
    return with_sum(2 * cur + 1, l, (l + r) / 2, k);
  else
    return with_sum(2 * cur + 2, (l + r) / 2, r, k - tree[2 * cur + 1]);
}
void solve() {
  int n, m;
  cin >> n;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  for (int &x : tree) x = 0;
  vector<pair<int, int> > precalc;
  vector<tuple<int, int, int> > queries;
  for (int i = 0; i < n; ++i) precalc.emplace_back(a[i], -i);
  sort(precalc.begin(), precalc.end());
  reverse(precalc.begin(), precalc.end());
  for (int i = 0; i < n; ++i) arr[i] = abs(precalc[i].second) + 1;
  cin >> m;
  vector<int> res(m);
  for (int q = 0; q < m; ++q) {
    int k, j;
    cin >> k >> j;
    queries.emplace_back(k, j, q);
  }
  sort(queries.begin(), queries.end());
  build(0, 0, n + 1);
  long long cur_pos = -1;
  for (int t = 0; t < m; ++t) {
    auto [k, j, q] = queries[t];
    for (int i = cur_pos + 1; i <= k - 1; ++i) add(0, 0, n + 1, 1, arr[i]);
    res[q] = a[with_sum(0, 0, n + 1, j) - 1];
    cur_pos = k - 1;
  }
  for (int x : res) cout << x << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
