#include <bits/stdc++.h>
#pragma GCC optimize("pivo na polu")
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e12;
const int MOD = 1000000007;
const long double eps = 1e-7;
const int MOD2 = (1 << 30) + 1;
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
vector<int> t;
int n, m;
void add(int i) {
  for (; i < n; i = (i | (i + 1))) t[i] += 1;
}
int get(int i) {
  int res = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) res += t[i];
  return res;
}
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
signed main() {
  fast_io();
  cin >> n;
  vector<pair<int, int>> nums(n);
  t.resize(n);
  vector<int> lolan(n);
  for (int i = 0; i < n; i++) {
    cin >> lolan[i];
    nums[i] = make_pair(lolan[i], i);
  }
  cin >> m;
  sort(nums.begin(), nums.end(), cmp);
  vector<tuple<int, int, int>> posts(m);
  for (int i = 0; i < m; i++) {
    int k, pos;
    cin >> k >> pos;
    posts[i] = make_tuple(k, pos, i);
  }
  sort(posts.begin(), posts.end());
  vector<int> ans(m);
  int last = 0;
  for (tuple<int, int, int> kekan : posts) {
    int k, pos, i;
    tie(k, pos, i) = kekan;
    for (int j = last; j < k; j++) {
      add(nums[j].second);
    }
    int l = 0, r = n - 1;
    int answer = 0;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      int post = get(mid);
      if (post < pos)
        l = mid + 1;
      else {
        r = mid - 1;
        answer = mid;
      }
    }
    last = k;
    ans[i] = lolan[answer];
  }
  for (int i : ans) cout << i << endl;
  return 0;
}
