#include <bits/stdc++.h>
using namespace std;
void read(int &x) { scanf("%d", &x); }
void read(long long int &x) { scanf("%I64d", &x); }
void read(long long int &a, long long int &b) { scanf("%I64d %I64d", &a, &b); }
void read(long long int &a, long long int &b, long long int &c) {
  scanf("%I64d %I64d %I64d", &a, &b, &c);
}
void read(long long int &a, long long int &b, long long int &c,
          long long int &d) {
  scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d);
}
void read(double &x) { scanf("%lf", &x); }
void read(char &x) { scanf("%c", &x); }
void read(string &x) {
  char y[1000006];
  scanf("%s", &y);
  x = y;
}
void print(long long int x, bool flag = false) {
  if (flag)
    printf("%I64d ", x);
  else
    printf("%I64d\n", x);
}
void print(int x, bool flag = false) {
  if (flag)
    printf("%d ", x);
  else
    printf("%d\n", x);
}
void print(double x, bool flag = false) {
  if (flag)
    printf("%0.14lf ", x);
  else
    printf("%0.14lf\n", x);
}
void print(char x) { printf("%c\n", x); }
void print(string x) {
  for (long long int i = 0; i < x.size(); i++) {
    printf("%c", x[i]);
  }
  printf("\n");
}
const long long int mx = 2e5 + 2;
struct queries {
  long long int k, pos, id;
} q[mx];
bool comp(queries q1, queries q2) { return q1.k > q2.k; }
long long int fen[mx];
void update(long long int id, long long int val) {
  while (id < mx) {
    fen[id] += val;
    id += (id & -id);
  }
}
long long int query(long long int id) {
  long long int res = 0;
  while (id > 0) {
    res += fen[id];
    id -= (id & -id);
  }
  return res;
}
long long int find_index(long long int pos) {
  long long int lo = 1, high = mx - 2, ans = mx - 2;
  while (lo <= high) {
    long long int mid = (lo + high) / 2;
    if (query(mid) >= pos)
      ans = mid, high = mid - 1;
    else
      lo = mid + 1;
  }
  return ans;
}
void solve() {
  long long int n;
  read(n);
  long long int a[n + 1], cnt = 0;
  unordered_map<long long int, long long int> mp;
  multiset<long long int> s;
  long long int posi = n;
  for (long long int i = 1; i <= n; i++) {
    read(a[i]);
    s.insert(a[i]);
    update(i, 1);
  }
  for (auto p : s) {
    if (mp[p] == 0) mp[p] = ++cnt;
  }
  vector<long long int> index[n + 1];
  for (long long int i = 1; i <= n; i++) index[mp[a[i]]].push_back(i);
  long long int m;
  read(m);
  for (long long int i = 0; i < m; i++) {
    long long int k, pos;
    read(k, pos);
    q[i].k = k;
    q[i].pos = pos;
    q[i].id = i + 1;
  }
  long long int ans[m + 1];
  sort(q, q + m, comp);
  for (long long int i = 0; i < m; i++) {
    while (q[i].k < posi) {
      posi--;
      long long int mini = *s.begin();
      s.erase(s.begin());
      long long int ind = index[mp[mini]].back();
      index[mp[mini]].pop_back();
      update(ind, -1);
    }
    long long int ind = find_index(q[i].pos);
    ans[q[i].id] = a[ind];
  }
  for (long long int i = 1; i <= m; i++) print(ans[i]);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
