#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << '\n';
  err(++it, args...);
}
const long long inf = 1e18L + 5;
const long long mod = 1e9 + 7;
const long long SIZEN = 200005;
long long arr[SIZEN], tree[SIZEN * 4];
vector<pair<long long, long long> > sortedVec, vec2, ques;
vector<vector<long long> > answer;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first > b.first) return true;
  if (b.first > a.first) return false;
  if (a.second > b.second) return false;
  return true;
}
bool comp2(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first > b.first) return true;
  if (b.first > a.first) return false;
  return a.second < b.second;
}
void update(int v, int tl, int tr, int pos, int val) {
  if (tl == tr) {
    tree[v] += val;
  } else {
    int tm = (tl + tr) / 2;
    if (pos <= tm) {
      update(v * 2 + 1, tl, tm, pos, val);
    } else {
      update(v * 2 + 2, tm + 1, tr, pos, val);
    }
    tree[v] = tree[v * 2 + 1] + tree[v * 2 + 2];
  }
}
long long get(int v, int tl, int tr, int k) {
  if (tl == tr) {
    return tl;
  } else {
    int tm = (tl + tr) / 2;
    if (tree[v * 2 + 1] >= k) {
      return get(v * 2 + 1, tl, tm, k);
    } else {
      return get(v * 2 + 2, tm + 1, tr, k - tree[v * 2 + 1]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sortedVec.push_back(make_pair(arr[i], i));
  }
  cin >> m;
  sort(sortedVec.begin(), sortedVec.end(), comp2);
  answer.resize(m, vector<long long>(3));
  for (int i = 0; i < m; i++) {
    int k, pos;
    cin >> k >> pos;
    ques.push_back(make_pair(k, pos));
    answer[i][0] = k;
    answer[i][1] = pos;
    answer[i][2] = i;
  }
  sort(answer.begin(), answer.end());
  vector<int> ans(m);
  int prev = 0;
  for (int i = 0; i < answer.size(); i++) {
    for (int j = prev; j < answer[i][0]; j++) {
      update(0, 0, n, sortedVec[j].second, 1);
      prev++;
    }
    ans[answer[i][2]] = arr[get(0, 0, n, answer[i][1])];
  }
  for (int i = 0; i < answer.size(); i++) {
    cout << ans[i] << "\n";
  }
  return 0;
}
