#include <bits/stdc++.h>
using namespace std;
inline void minimize(int &x, int y) { x = min(x, y); }
inline void maximize(int &x, int y) { x = max(x, y); }
const int N = 200000 + 1067;
int n, m;
int val[N], pos[N], it[N], res[N];
vector<int> to[N];
struct Node {
  int id, a;
} node[N];
bool comp(Node c1, Node c2) {
  return c1.a < c2.a || (c1.a == c2.a && c1.id > c2.id);
}
void update(int x, int c) {
  while (x <= n) {
    it[x] += c;
    x += x & (-x);
  }
}
int get(int x) {
  int res = 0;
  while (x) {
    res += it[x];
    x -= x & (-x);
  }
  return res;
}
int bs(int l, int r, int c) {
  while (l < r) {
    if (l == r - 1)
      if (get(l) >= c)
        return l;
      else
        return r;
    int mid = (l + r) / 2;
    if (get(mid) >= c)
      r = mid;
    else
      l = mid + 1;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> node[i].a;
    node[i].id = i;
    val[i] = node[i].a;
    update(i, 1);
  }
  sort(node + 1, node + n + 1, comp);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int k;
    cin >> k >> pos[i];
    to[k].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int kk = n - i + 1;
    for (auto j : to[kk]) {
      res[j] = val[bs(1, n, pos[j])];
    }
    update(node[i].id, -1);
  }
  for (int i = 1; i <= m; i++) cout << res[i] << endl;
  return 0;
}
