#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[200002];
int a[200002];
int res[200002];
int ft[200002];
void update(int i, int v) {
  for (; i <= 200000; i += (i & -i)) ft[i] += v;
}
int query(int i) {
  int ans = 0;
  for (; i > 0; i -= (i & -i)) ans += ft[i];
  return ans;
}
int main() {
  priority_queue<pair<int, int> > pq;
  int n, m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pq.push(pair<int, int>(a[i], -i));
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int k, pos;
    scanf("%d%d", &k, &pos);
    v[k].push_back(pair<int, int>(pos, i));
  }
  int cnt = 0;
  while (!pq.empty()) {
    int x = pq.top().first, idx = -pq.top().second;
    pq.pop();
    cnt++;
    update(idx, 1);
    for (int j = 0; j < v[cnt].size(); j++) {
      int idx = v[cnt][j].second, pos = v[cnt][j].first;
      int lo = 1, hi = n;
      int ans = 0;
      while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (query(mid) >= pos)
          ans = mid, hi = mid - 1;
        else
          lo = mid + 1;
      }
      res[idx] = a[ans];
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", res[i]);
}
