#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 1e6 + 5;
long long int tree[MAXN];
void inc(long long int pos) {
  for (; pos < MAXN; pos |= (pos + 1)) {
    tree[pos] += 1;
  }
}
long long int get(long long int pos) {
  long long int ans = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
    ans += tree[pos];
  }
  return ans;
}
long long int get_kth(long long int k) {
  long long int l = -1, r = MAXN;
  while (r - l > 1) {
    long long int mid = (l + r) / 2;
    if (get(mid) < k) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back({-a[i], i});
  }
  sort(v.begin(), v.end());
  for (auto &i : v) {
    i.first *= -1;
  }
  int m;
  cin >> m;
  vector<pair<pair<int, int>, int> > que;
  for (int i = 0; i < m; i++) {
    int k, j;
    cin >> k >> j;
    que.push_back({{k, j}, i});
  }
  sort(que.begin(), que.end());
  set<int> s;
  int l = 0;
  int ans[m];
  for (int i = 0; i < m; i++) {
    while (l < que[i].first.first) inc(v[l++].second);
    ans[que[i].second] = a[get_kth(que[i].first.second)];
  }
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
