#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 500031;
int n;
int ar[N];
vector<pair<int, int> > order;
int tests;
int len[N], ps[N];
vector<int> queries[N];
int t[N * 4];
int ans[N];
void add(int v, int tl, int tr, int ps, int val) {
  if (tl == tr) {
    t[v] += val;
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    add(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    add(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
int get(int v, int tl, int tr, int am) {
  if (tl == tr) return tl;
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (t[v * 2] >= am) return get(v * 2, tl, sdfjahlfasfh, am);
  am -= t[v * 2];
  return get(v * 2 + 1, sdfjahlfasfh + 1, tr, am);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    order.push_back(make_pair(ar[i], -i));
  }
  sort(order.begin(), order.end());
  reverse(order.begin(), order.end());
  cin >> tests;
  for (int test = 1; test <= tests; test++) {
    cin >> len[test] >> ps[test];
    queries[len[test]].push_back(test);
  }
  for (int i = 0; i < order.size(); i++) {
    int pss = order[i].second;
    pss *= -1;
    add(1, 1, n, pss, 1);
    for (int j = 0; j < queries[i + 1].size(); j++) {
      int qu_id = queries[i + 1][j];
      int which = ps[qu_id];
      int where = get(1, 1, n, which);
      ans[qu_id] = ar[where];
    }
  }
  for (int i = 1; i <= tests; i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
