#include <bits/stdc++.h>
using namespace std;
int n;
class BitTree {
  vector<int> data;
  int size;

 public:
  BitTree(int size_) {
    size = size_;
    data.resize(size_ + 1);
  }
  int getMinPosition(int sum) {
    int ret = 0;
    for (int step = 1 << 20; step > 0; step >>= 1) {
      if (ret + step <= size && data[ret + step] < sum) {
        sum -= data[ret + step];
        ret += step;
        if (!sum) {
          return ret + 1;
        }
      }
    }
    return ret + 1;
  }
  void update(const int& position, const int& value) {
    for (int i = position; i <= size; i += (i & -i)) {
      data[i] += value;
    }
  }
  int query(const int& position) {
    int ret = 0;
    for (int i = position; i > 0; i -= (i & -i)) {
      ret += data[i];
    }
    return ret;
  }
  int query(const int& a, const int& b) {
    if (a > b) return 0;
    return query(b) - query(a - 1);
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<int> og(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
    og[i] = a[i].first;
  }
  auto cmp = [&](const pair<int, int>& u, const pair<int, int>& v) {
    if (u.first == v.first) return u.second < v.second;
    return u.first > v.first;
  };
  sort(a.begin(), a.end(), cmp);
  int q;
  cin >> q;
  vector<vector<pair<int, int>>> qs(n);
  vector<int> ans(q);
  BitTree BT(n);
  for (int i = 0; i < q; ++i) {
    int k, pos;
    cin >> k >> pos;
    qs[k - 1].push_back(make_pair(pos - 1, i));
  }
  for (int i = 0; i < n; ++i) {
    BT.update(a[i].second + 1, 1);
    for (auto it : qs[i]) ans[it.second] = BT.getMinPosition(it.first + 1);
  }
  for (int i = 0; i < q; ++i) cout << og[ans[i] - 1] << '\n';
}
