#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const long long MINF = 0x7f7f7f7f7f7f7f7fll;
const int N = 2e5 + 50;
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > q[N];
int ans[N];
int a[N];
struct BIT {
  int t[N];
  void add(int x) {
    for (int i = x; i < N; i += (i & -i)) ++t[i];
  }
  int query(int x) {
    int ans = 0;
    for (int i = x; i; i -= (i & -i)) ans += t[i];
    return ans;
  }
} t;
int main() {
  int n, m, x, y;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i)
    scanf("%d", &a[i]), pq.push(make_pair(a[i], -i));
  scanf("%d", &m);
  for (int i = (1); i <= (m); ++i)
    scanf("%d%d", &x, &y), q[x].push_back(make_pair(y, i));
  for (int i = (1); i <= (n); ++i) {
    int np = -pq.top().second;
    pq.pop();
    t.add(np);
    for (pair<int, int> p : q[i]) {
      int l = 1, r = n;
      while (l < r) {
        int mid = (l + r) >> 1;
        if (t.query(mid) >= p.first)
          r = mid;
        else
          l = mid + 1;
      }
      ans[p.second] = a[l];
    }
  }
  for (int i = (1); i <= (m); ++i) printf("%d\n", ans[i]);
}
