#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20;
const long long INF = INT_MAX;
struct node {
  node *l, *r;
  long long x, y;
  long long sum;
  long long val;
  long long sz;
  node(long long s, long long pos) {
    l = nullptr;
    r = nullptr;
    y = rand();
    sum = s * s;
    val = s;
    x = pos;
    sz = 1;
  }
};
long long getx(node* v) {
  if (v == nullptr) return 0;
  return v->x;
}
long long getsum(node* v) {
  if (v == nullptr) return 0;
  return v->sum;
}
long long getval(node* v) {
  if (v == nullptr) return 0;
  return v->val;
}
long long getsz(node* v) {
  if (v == nullptr) return 0;
  return v->sz;
}
void add_val(node*& v, long long newv) {
  if (v == nullptr) return;
  v->val += newv;
  v->sum = getval(v) * getval(v);
  v->sum += getsum(v->l) + getsum(v->r);
}
void change_val(node*& v, long long newv) {
  if (v == nullptr) return;
  v->val = newv;
  v->sum = newv * newv;
  v->sum += getsum(v->l) + getsum(v->r);
}
void upd(node* v) {
  if (v == nullptr) return;
  v->sum = getsum(v->l) + getsum(v->r) + getval(v) * getval(v);
  v->sz = getsz(v->l) + getsz(v->r) + 1;
}
pair<node*, node*> split(node* root, long long key) {
  if (root == nullptr) return {nullptr, nullptr};
  if (root->x <= key) {
    pair<node*, node*> splitted = split(root->r, key);
    root->r = splitted.first;
    upd(root);
    return {root, splitted.second};
  } else {
    pair<node*, node*> splitted = split(root->l, key);
    root->l = splitted.second;
    upd(root);
    return {splitted.first, root};
  }
}
node* merge(node* left, node* right) {
  if (left == nullptr || right == nullptr) {
    return right != nullptr ? right : left;
  }
  if (left->y > right->y) {
    left->r = merge(left->r, right);
    upd(left);
    return left;
  } else {
    right->l = merge(left, right->l);
    upd(right);
    return right;
  }
}
void insert(node*& root, long long key, long long val) {
  auto splitted = split(root, key - 1);
  root = merge(merge(splitted.first, new node(val, key)), splitted.second);
}
long long find(node*& root, long long n) {
  long long ln = getsz(root->l);
  if (ln + 1 == n) {
    return getval(root);
  }
  if (n < ln + 1) {
    return find(root->l, n);
  } else
    return find(root->r, n - ln - 1);
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first > b.first;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a.push_back({x, i});
  }
  sort(a.begin(), a.end(), cmp);
  long long t;
  cin >> t;
  vector<pair<pair<long long, long long>, long long>> q;
  for (long long i = 0; i < t; ++i) {
    long long k, pos;
    cin >> k >> pos;
    q.push_back({{k, pos}, i});
  }
  sort(q.begin(), q.end());
  node* root = nullptr;
  long long k = 0;
  vector<long long> qqq(q.size());
  for (auto& i : q) {
    long long curk = i.first.first;
    long long pos = i.first.second;
    long long id = i.second;
    while (k < curk) {
      insert(root, a[k].second + 1, a[k].first);
      k++;
    }
    qqq[id] = find(root, pos);
  }
  for (auto& i : qqq) cout << i << endl;
  return 0;
}
