#include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
const int maxn = 101010;
const int maxn4 = 4 * maxn;
const long long inf = 2020202020202020202LL;
struct cell {
  int l, r, h;
};
vector<vector<cell> > tr(maxn4), td(maxn4);
bool cmpl(cell a, cell b) {
  if (a.l < b.l) return 1;
  if (a.l == b.l)
    if (a.r < b.r) return 1;
  if (a.l == b.l && a.r == b.r)
    if (a.h < b.h) return 1;
  return 0;
}
bool cmpr(cell a, cell b) {
  if (a.r < b.r) return 1;
  if (a.r == b.r)
    if (a.l < b.l) return 1;
  if (a.l == b.l && a.r == b.r)
    if (a.h < b.h) return 1;
  return 0;
}
vector<cell> combine(vector<cell> &a, vector<cell> &b) {
  vector<cell> temp;
  temp.resize(a.size() + b.size());
  for (int i = 0; i < a.size(); i++) temp[i] = a[i];
  for (int i = a.size(); i < temp.size(); i++) temp[i] = b[i - a.size()];
  sort(temp.begin(), temp.end(), &cmpr);
  return temp;
}
void build(vector<cell> &a, int v, int l, int r) {
  if (l == r) {
    tr[v].resize(1);
    td[v].resize(1);
    tr[v][0] = td[v][0] = a[l];
    td[v][0].r = td[v][0].r - td[v][0].l;
  } else {
    int m = (l + r) / 2;
    build(a, 2 * v + 1, l, m);
    build(a, 2 * v + 2, m + 1, r);
    tr[v] = combine(tr[2 * v + 1], tr[2 * v + 2]);
    td[v] = combine(td[2 * v + 1], td[2 * v + 2]);
  }
}
void smoother() {
  for (int i = 0; i < maxn4; i++) {
    int mx = 0;
    for (int j = tr[i].size() - 1; j >= 0; j--) {
      mx = max(mx, tr[i][j].h);
      tr[i][j].h = mx;
    }
    mx = 0;
    for (int j = td[i].size() - 1; j >= 0; j--) {
      mx = max(mx, td[i][j].h);
      td[i][j].h = mx;
    }
  }
}
int quer(int v, int tl, int tr2, int l, int r, int val) {
  if (l > r) return 0;
  if (l == tl && r == tr2) {
    cell temp;
    temp.h = 0;
    temp.r = val;
    temp.l = 0;
    vector<cell>::iterator x =
        lower_bound(tr[v].begin(), tr[v].end(), temp, &cmpr);
    if (x != tr[v].end()) return x->h;
    return 0;
  }
  int tm = (tl + tr2) / 2;
  return max(quer(v * 2 + 1, tl, tm, l, min(r, tm), val),
             quer(v * 2 + 2, tm + 1, tr2, max(l, tm + 1), r, val));
}
int qued(int v, int tl, int tr2, int l, int r, int val) {
  if (l > r) return 0;
  if (l == tl && r == tr2) {
    cell temp;
    temp.h = 0;
    temp.r = val - 1;
    temp.l = 0;
    vector<cell>::iterator x =
        lower_bound(td[v].begin(), td[v].end(), temp, &cmpr);
    if (x != td[v].end()) return x->h;
    return 0;
  }
  int tm = (tl + tr2) / 2;
  return max(qued(v * 2 + 1, tl, tm, l, min(r, tm), val),
             qued(v * 2 + 2, tm + 1, tr2, max(l, tm + 1), r, val));
}
int n, m;
vector<cell> h;
vector<cell> pack;
vector<int> lpack;
void rfind() {
  for (int i = 0; i < n; i++) {
    int y = 1;
    while (y) {
      if (lpack.size()) {
        int d = lpack[lpack.size() - 1];
        if (pack[d].h > pack[i].h) {
          pack[d].r = i - 1;
          lpack.pop_back();
        } else
          y = 0;
      } else
        y = 0;
    }
    lpack.push_back(i);
  }
  while (lpack.size()) {
    int d = lpack[lpack.size() - 1];
    pack[d].r = n - 1;
    lpack.pop_back();
  }
}
int src(int p) {
  cell temp;
  temp.l = p;
  temp.r = 0;
  temp.h = 0;
  vector<cell>::iterator x;
  x = lower_bound(h.begin(), h.end(), temp, &cmpl);
  return x - h.begin();
}
int src2(int p) {
  cell temp;
  temp.l = p;
  temp.r = md;
  temp.h = md;
  vector<cell>::iterator x;
  x = lower_bound(h.begin(), h.end(), temp, &cmpl);
  return x - h.begin();
}
int main() {
  ios::ios_base::sync_with_stdio(false);
  cin >> n;
  h.resize(n);
  pack.resize(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    h[i].h = x;
  }
  for (int i = 0; i < n; i++) pack[i] = h[i];
  rfind();
  for (int i = 0; i < n; i++) h[i].r = pack[i].r;
  reverse(pack.begin(), pack.end());
  rfind();
  for (int i = 0; i < n; i++) h[n - 1 - i].l = n - 1 - pack[i].r;
  sort(h.begin(), h.end(), &cmpl);
  build(h, 0, 0, n - 1);
  smoother();
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r, w;
    cin >> l >> r >> w;
    l--;
    r--;
    int l1, l2, r1, r2;
    l1 = src(0);
    r1 = src2(l - 1) - 1;
    l2 = src(l);
    r2 = src2(r - w + 1) - 1;
    cout << max(quer(0, 0, n - 1, l1, r1, w + l - 1),
                qued(0, 0, n - 1, l2, r2, w))
         << endl;
  }
  return 0;
}
