#include <bits/stdc++.h>
using namespace std;
int a[300005];
int n;
int ans[300005];
vector<pair<int, int> > v[300005];
const int max_node = 2000000;
int tree[max_node];
void update(int node, int start, int _end, int idx, int val) {
  if (start == _end) {
    tree[node] += val;
  } else {
    int mid = (start + _end) / 2;
    if (start <= idx && idx <= mid) {
      update(node * 2, start, mid, idx, val);
    } else {
      update(node * 2 + 1, mid + 1, _end, idx, val);
    }
    tree[node] = tree[2 * node] + tree[2 * node + 1];
  }
}
int query(int node, int start, int _end, int l, int r, int need) {
  if (start == _end) {
    return a[start];
  }
  int mid = (start + _end) / 2;
  int x1 = tree[2 * node], x2 = tree[node * 2 + 1];
  if (x1 >= need) {
    return query(2 * node, start, mid, l, r, need);
  } else {
    need -= x1;
    return query(2 * node + 1, mid + 1, _end, l, r, need);
  }
}
void solve() {
  vector<pair<int, int> > R;
  for (int i = 1; i <= n; i++) {
    R.push_back(make_pair(-a[i], i));
  }
  sort(R.begin(), R.end());
  int id = 0;
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, R[id].second, 1);
    for (int j = 0; j < v[i].size(); j++) {
      pair<int, int> temp = v[i][j];
      int res = query(1, 1, n, 1, n, temp.first);
      ans[temp.second] = res;
    }
    id++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(make_pair(y, i));
  }
  for (int i = 0; i < 300000; i++) {
    sort(v[i].begin(), v[i].end());
  }
  solve();
  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
