#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 2e5 + 10, M = 17;
struct node {
  int num, pos;
  friend bool operator<(node a, node b) {
    if (a.num == b.num) return a.pos < b.pos;
    return a.num > b.num;
  }
} a[N];
struct query {
  int k, pos, id;
  friend bool operator<(query a, query b) { return a.k > b.k; }
};
priority_queue<query> q;
int tr[N], num[N], ans[N];
int x, n;
int lowbit(int x) { return x & -x; }
void update(int x, int c) {
  for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;
}
int query(int x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += tr[i];
  return res;
}
int find(int pos) {
  int l = 1, r = n;
  int res = 0;
  while (l <= r) {
    int mid = l + r >> 1;
    if (query(mid) >= pos) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return res;
}
void solve() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    a[i] = {num[i], i};
  }
  sort(a + 1, a + 1 + n);
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int k, pos;
    scanf("%d%d", &k, &pos);
    q.push({k, pos, i});
  }
  x = 0;
  while (!q.empty()) {
    int cnt = q.top().k, pos = q.top().pos, id = q.top().id;
    q.pop();
    while (x < cnt) {
      ++x;
      update(a[x].pos, 1);
    }
    int p = find(pos);
    ans[id] = num[p];
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
int main() {
  solve();
  return 0;
}
