#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
  if (b == 0 || a == 1) return mod == 1 ? 0 : 1;
  if (b % 2 == 0) {
    long long k = powmod(a, b / 2, mod);
    return (k * k) % mod;
  } else {
    long long k = powmod(a, b / 2, mod);
    return ((k * k) % mod * a) % mod;
  }
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
bool is_prime(long long n) {
  long long bound = sqrt(n);
  long long d = 2;
  while (d <= bound && n % d != 0) ++d;
  return d * d > n;
}
const int MOD = 1000000007;
const int INF = 1000000050;
const int MX = 100010;
const double EPS = 1e-9;
mt19937 rnd;
struct Node {
  int prior, key, sz;
  Node *l, *r;
  Node(int key) : key(key), prior(rnd()), sz(1), l(nullptr), r(nullptr){};
};
int GetSize(Node* t) {
  if (t == nullptr) {
    return 0;
  } else {
    return t->sz;
  }
}
void Update(Node* t) { t->sz = GetSize(t->l) + GetSize(t->r) + 1; }
pair<Node*, Node*> Split(Node* t, int key) {
  if (t == nullptr) {
    return {nullptr, nullptr};
  }
  if (t->key < key) {
    auto splited = Split(t->r, key);
    t->r = splited.first;
    Update(t);
    return {t, splited.second};
  } else {
    auto splited = Split(t->l, key);
    t->l = splited.second;
    Update(t);
    return {splited.first, t};
  }
}
Node* Merge(Node* t1, Node* t2) {
  if (t1 == nullptr) {
    return t2;
  }
  if (t2 == nullptr) {
    return t1;
  }
  if (t1->prior > t2->prior) {
    t1->r = Merge(t1->r, t2);
    Update(t1);
    return t1;
  } else {
    t2->l = Merge(t1, t2->l);
    Update(t2);
    return t2;
  }
}
Node* Insert(Node* t, int key) {
  Node* key_node = new Node(key);
  auto splited_left = Split(t, key);
  auto splited_right = Split(splited_left.second, key + 1);
  t = Merge(splited_left.first, key_node);
  t = Merge(t, splited_right.second);
  Update(t);
  return t;
}
int FindKth(Node* t, int k) {
  if (t == nullptr) {
    return INF;
  }
  if (GetSize(t->l) + 1 == k) {
    return t->key;
  } else if (GetSize(t->l) >= k) {
    return FindKth(t->l, k);
  } else {
    return FindKth(t->r, k - 1 - GetSize(t->l));
  }
}
map<int, set<int>> ps;
struct req {
  int k;
  int pos;
  int id;
};
bool cmp(req a, req b) { return a.k < b.k; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ps[a[i]].insert(i);
    q[i] = a[i];
  }
  sort(begin(q), end(q));
  reverse(begin(q), end(q));
  vector<int> arr;
  int pr = -1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int pos = *(ps[q[i]].begin());
    arr.push_back(pos);
    ps[q[i]].erase(ps[q[i]].begin());
  }
  int m;
  cin >> m;
  vector<int> ans(m);
  vector<req> reqs(m);
  for (int i = 0; i < m; i++) {
    int pos, k;
    cin >> k >> pos;
    reqs[i] = {k, pos, i};
  }
  sort(begin(reqs), end(reqs), cmp);
  int prv = 0;
  Node* t = nullptr;
  for (req r : reqs) {
    int k = r.k;
    int pos = r.pos;
    for (int i = prv; i < k; i++) {
      t = Insert(t, arr[i]);
    }
    prv = k;
    int id = r.id;
    ans[id] = FindKth(t, pos);
  }
  for (int i = 0; i < m; i++) cout << a[ans[i]] << '\n';
}
