#include <bits/stdc++.h>
using namespace std;
class quer {
 public:
  long long k, pos, indx;
};
bool cmpr(quer a, quer b) { return a.k < b.k; }
long long getSum(long long bit[], long long indx) {
  long long sum = 0;
  while (indx > 0) {
    sum += bit[indx];
    indx -= (indx & (-indx));
  }
  return sum;
}
void update(long long bit[], long long indx, long long val) {
  while (indx < 200002) {
    bit[indx] += val;
    indx += (indx & (-indx));
  }
  return;
}
long long get_ans(long long bit[], long long n, long long pos) {
  long long lo = 1, hi = n - 1;
  long long mid, ans;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (getSum(bit, mid) >= pos) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long ar[n];
  for (long long i = 0; i < n; i++) cin >> ar[i];
  ;
  map<long long, set<long long> > mp;
  for (long long i = 0; i < n; i++) mp[ar[i]].insert(i + 1);
  vector<long long> v;
  for (long long i = 0; i < n; i++) v.push_back(ar[i]);
  sort(v.begin(), v.end());
  long long bit[200002];
  memset(bit, 0, sizeof(bit));
  vector<quer> vq;
  quer q;
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    cin >> q.k >> q.pos;
    q.pos--;
    q.indx = i;
    vq.push_back(q);
  }
  sort(vq.begin(), vq.end(), cmpr);
  long long res[m];
  long long ind = 0, cnt = 0;
  for (long long i = n - 1; ~i; i--) {
    if (n - i <= vq[ind].k) {
      cnt++;
      update(bit, *(mp[v[i]].begin()), 1);
      mp[v[i]].erase(mp[v[i]].begin());
    }
    if (n - i == vq[ind].k) {
      while (ind < m and n - i == vq[ind].k) {
        res[vq[ind].indx] = ar[get_ans(bit, 200002, vq[ind].pos + 1) - 1];
        ind++;
      }
    }
  }
  for (long long i = 0; i < m; i++) cout << res[i] << "\n";
  return 0;
}
