#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, m, a[200200];
vector<pair<int, int> > v;
int ans[200200];
int t[4 * 200200];
vector<pair<int, int> > queries[200200];
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.first > b.first || (a.first == b.first && a.second < b.second);
}
void add(int v, int tl, int tr, int pos) {
  if (tl == tr)
    t[v]++;
  else {
    int mid = (tl + tr) >> 1;
    if (pos <= mid)
      add(2 * v, tl, mid, pos);
    else
      add(2 * v + 1, mid + 1, tr, pos);
    t[v] = t[2 * v] + t[2 * v + 1];
  }
}
int get(int v, int tl, int tr, int k) {
  if (tl == tr) return tl;
  int mid = (tl + tr) >> 1;
  if (t[2 * v] >= k) return get(2 * v, tl, mid, k);
  return get(2 * v + 1, mid + 1, tr, k - t[2 * v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    v.push_back(make_pair(a[i], i));
  }
  sort(v.begin(), v.end(), cmp);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k, pos;
    scanf("%d%d", &k, &pos);
    queries[k].push_back(make_pair(pos, i));
  }
  for (int i = 1; i <= n; i++) {
    add(1, 0, n - 1, v[i - 1].second);
    for (int j = 0; j < queries[i].size(); j++) {
      int ind = get(1, 0, n - 1, queries[i][j].first);
      ans[queries[i][j].second] = a[ind];
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
