#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1e4;
struct sad {
  int m, l, r, w;
  sad operator+(const sad &b) const {
    sad c;
    c.w = w + b.w;
    if (l == w)
      c.l = w + b.l;
    else
      c.l = l;
    if (b.r == b.w)
      c.r = b.w + r;
    else
      c.r = b.r;
    c.m = max(max(m, b.m), r + b.l);
    return c;
  }
  sad(int a) {
    w = 1;
    m = l = r = (a ? 1 : 0);
  }
  sad(){};
};
sad rs[maxn << 2];
void pushup(int rt) { rs[rt] = rs[rt << 1] + rs[rt << 1 | 1]; }
void build(int l, int r, int rt) {
  if (l == r) {
    rs[rt] = sad(0);
    return;
  }
  int m = l + r >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void update(int pos, int c, int l, int r, int rt) {
  if (l == r) {
    rs[rt] = sad(c);
    return;
  }
  int m = l + r >> 1;
  if (pos <= m)
    update(pos, c, l, m, rt << 1);
  else
    update(pos, c, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
sad query(int L, int R, int l, int r, int rt) {
  if (L > R)
    while (1)
      ;
  if (L <= l && r <= R) return rs[rt];
  int m = l + r >> 1;
  if (L <= m && m < R)
    return query(L, R, l, m, rt << 1) + query(L, R, m + 1, r, rt << 1 | 1);
  if (L <= m) return query(L, R, l, m, rt << 1);
  return query(L, R, m + 1, r, rt << 1 | 1);
}
void print(int l, int r, int rt) {
  if (l == r) {
    printf("%d ", rs[rt].m);
    return;
  }
  int m = l + r >> 1;
  print(l, m, rt << 1);
  print(m + 1, r, rt << 1 | 1);
}
struct __sad {
  int l, r, w, pos, v;
  int st, id;
  void print() {
    if (st == 1)
      printf("(1,pos %d,v %d)", pos, v);
    else
      printf("(2 l %d r %d w %d id %d)", l, r, w, id);
  }
} p[maxn], p1[maxn], p2[maxn];
int n, m;
int ans[maxn];
void Bin(int st, int ed, int l, int r) {
  if (st > ed) return;
  if (l == r) {
    for (int i = st; i <= ed; i++)
      if (p[i].st == 2) ans[p[i].id] = l;
    return;
  }
  int mid = l + (r - l) / 2;
  int ta1 = 0, ta2 = 0;
  for (int i = st; i <= ed; i++) {
    if (p[i].st == 1) {
      if (p[i].v > mid) {
        p2[ta2++] = p[i];
        update(p[i].pos, 1, 0, n - 1, 1);
      } else
        p1[ta1++] = p[i];
    } else {
      int t = query(p[i].l, p[i].r, 0, n - 1, 1).m;
      if (t >= p[i].w)
        p2[ta2++] = p[i];
      else
        p1[ta1++] = p[i];
    }
  }
  for (int i = st; i <= ed; i++) {
    if (p[i].st == 1)
      if (p[i].v > mid) update(p[i].pos, 0, 0, n - 1, 1);
  }
  for (int i = 0; i < ta1; i++) p[i + st] = p1[i];
  for (int i = 0; i < ta2; i++) p[i + st + ta1] = p2[i];
  Bin(st + ta1, ed, mid + 1, r);
  for (int i = st + ta1; i <= ed; i++) {
    if (p[i].st == 1) update(p[i].pos, 1, 0, n - 1, 1);
  }
  Bin(st, st + ta1 - 1, l, mid);
}
int main() {
  while (~scanf("%d", &n)) {
    int len = 0;
    for (int i = 0; i < n; i++) {
      p[len].st = 1;
      p[len].pos = i;
      scanf("%d", &p[len].v);
      len++;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      p[len].st = 2;
      p[len].id = i;
      scanf("%d%d%d", &p[len].l, &p[len].r, &p[len].w);
      p[len].l--;
      p[len].r--;
      len++;
    }
    build(0, n - 1, 1);
    Bin(0, len - 1, 1, 1e9 + 20);
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
