#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int a[MAXN + 5], bit[MAXN + 5];
int lowbit(int x) { return x & -x; }
void add(int i, int x) {
  while (i <= MAXN) {
    bit[i] += x;
    i += lowbit(i);
  }
}
int sum(int i) {
  int ans = 0;
  while (i) {
    ans += bit[i];
    i -= lowbit(i);
  }
  return ans;
}
void compress(vector<int>& a, vector<int>& b) {
  vector<int> v(a.begin(), a.end());
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int n = a.size();
  for (int i = 0; i < n; i++) {
    b[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
  }
}
bool cmp(pair<int, int>& a, pair<int, int>& b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
void work(pair<int, int>& q, map<pair<int, int>, int>& mp) {
  int k = q.first, p = q.second;
  int l = 1, r = MAXN, res = -1;
  while (l <= r) {
    int m = l + r >> 1;
    if (sum(m) < p)
      l = m + 1;
    else {
      res = m;
      r = m - 1;
    }
  }
  assert(res != -1);
  mp[q] = res;
}
int main() {
  int n, m;
  while (cin >> n) {
    memset(bit, 0, sizeof bit);
    vector<int> a(n), new_a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    compress(a, new_a);
    vector<pair<int, int> > b(n);
    for (int i = 0; i < n; i++) {
      b[i].first = a[i];
      b[i].second = i + 1;
    }
    sort(b.begin(), b.end(), cmp);
    cin >> m;
    vector<pair<int, int> > q(m);
    for (int i = 0; i < m; i++) cin >> q[i].first >> q[i].second;
    vector<pair<int, int> > sorted_q(q.begin(), q.end());
    sort(sorted_q.begin(), sorted_q.end());
    map<pair<int, int>, int> res;
    int cur = 0;
    for (int i = 0; i < n; i++) {
      add(b[i].second, 1);
      while (cur < m && i + 1 == sorted_q[cur].first) {
        work(sorted_q[cur], res);
        cur++;
      }
    }
    for (auto it : q) {
      int id = res[it];
      cout << a[id - 1] << endl;
    }
  }
  return 0;
}
