#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(42);
const int inf = 1000000000;
const int MAXSZ = 2e5 + 10;
int n, m, ar[MAXSZ], ans[MAXSZ];
vector<pair<int, int> > reqs[MAXSZ];
struct node {
  int val, cnt, pr;
  node *l = nullptr, *r = nullptr;
  node() {}
  node(int x) : val(x), cnt(1), pr(rnd()) {}
};
node *treap;
inline int getcnt(node *r) { return (r ? r->cnt : 0); }
inline void update(node *&x) {
  if (x) x->cnt = 1 + getcnt(x->l) + getcnt(x->r);
}
node *merge(node *tl, node *tr) {
  if (!tl || !tr) return tl ? tl : tr;
  if (tl->pr > tr->pr) {
    tl->r = merge(tl->r, tr), update(tl);
    return tl;
  } else {
    tr->l = merge(tl, tr->l), update(tr);
    return tr;
  }
}
inline void addnew(int val) {
  node *newnode = new node(val);
  treap = merge(treap, newnode);
}
pair<node *, node *> split(node *t, int val) {
  if (!t) return {nullptr, nullptr};
  if (getcnt(t->l) >= val) {
    pair<node *, node *> res = split(t->l, val);
    t->l = res.second, update(t);
    return {res.first, t};
  } else {
    pair<node *, node *> res = split(t->r, val - getcnt(t->l) - 1);
    t->r = res.first, update(t);
    return {t, res.second};
  }
}
void remove(int val, node *&t = treap) {
  if (!t) return;
  if (t->val == val) {
    t = merge(t->l, t->r);
    return;
  }
  if (val < t->val)
    remove(val, t->l);
  else
    remove(val, t->r);
  update(t);
}
int getans(int val) {
  pair<node *, node *> tmp = split(treap, val);
  pair<node *, node *> t = split(tmp.second, 1);
  int ret = t.first->val;
  treap = merge(tmp.first, merge(t.first, t.second));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  cin >> m;
  for (int i = 0; i < m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    reqs[t1].push_back({t2, i});
  }
  set<pair<int, int> > cur;
  for (int i = 0; i < n; i++) cur.insert({ar[i], -i}), addnew(i);
  for (int i = n; i > 0; i--) {
    for (auto tmp : reqs[i]) {
      ans[tmp.second] = getans(tmp.first - 1);
    }
    int tmp = -cur.begin()->second;
    cur.erase(cur.begin());
    remove(tmp);
  }
  for (int i = 0; i < m; i++) cout << ar[ans[i]] << endl;
  return 0;
}
