Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence of n panels of 1 meter width and of arbitrary height. The i-th panel's height is hi meters. The adjacent planks follow without a gap between them.

After Bizon painted the fence he decided to put a "for sale" sign on it. The sign will be drawn on a rectangular piece of paper and placed on the fence so that the sides of the sign are parallel to the fence panels and are also aligned with the edges of some panels. Bizon the Champion introduced the following constraints for the sign position:

  1. The width of the sign should be exactly w meters. 
  2. The sign must fit into the segment of the fence from the l-th to the r-th panels, inclusive (also, it can't exceed the fence's bound in vertical direction). 



The sign will be really pretty, So Bizon the Champion wants the sign's height to be as large as possible.

You are given the description of the fence and several queries for placing sign. For each query print the maximum possible height of the sign that can be placed on the corresponding segment of the fence with the given fixed width of the sign.

Input

The first line of the input contains integer n — the number of panels in the fence (1 ≤ n ≤ 105). 

The second line contains n space-separated integers hi, — the heights of the panels (1 ≤ hi ≤ 109). 

The third line contains an integer m — the number of the queries (1 ≤ m ≤ 105). 

The next m lines contain the descriptions of the queries, each query is represented by three integers l, r and w (1 ≤ l ≤ r ≤ n, 1 ≤ w ≤ r - l + 1) — the segment of the fence and the width of the sign respectively.

Output

For each query print the answer on a separate line — the maximum height of the sign that can be put in the corresponding segment of the fence with all the conditions being satisfied.

Examples

Input

5
1 2 2 3 3
3
2 5 3
2 5 2
1 5 5


Output

2
3
1

Note

The fence described in the sample looks as follows: 

<image>

The possible positions for the signs for all queries are given below.

<image> The optimal position of the sign for the first query.  <image> The optimal position of the sign for the second query.  <image> The optimal position of the sign for the third query. 
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
long long n, q, k;
struct node {
  long long ps, sf, ans;
  node() {
    ps = 0;
    sf = 0;
    ans = 0;
  }
} seg[maxn * 32];
long long L[maxn * 32], R[maxn * 32];
long long lst = 1, root[maxn];
void build(long long v = 1, long long tl = 1, long long tr = n) {
  if (tl == tr) return;
  long long tm = (tl + tr) >> 1;
  L[v] = ++lst;
  R[v] = ++lst;
  build(L[v], tl, tm);
  build(R[v], tm + 1, tr);
}
node up(node A, node B, long long l, long long r, long long tm) {
  node res;
  res.ans = max({A.ans, B.ans, A.sf + B.ps});
  res.ps = A.ps;
  if (A.ps == (tm - l + 1)) res.ps += B.ps;
  res.sf = B.sf;
  if (B.sf == (r - tm)) res.sf += A.sf;
  return res;
}
void upd(long long pos, long long v, long long id, long long tl = 1,
         long long tr = n) {
  if (tl == tr) {
    seg[v].ps = 1;
    seg[v].sf = 1;
    seg[v].ans = 1;
    return;
  }
  long long tm = (tl + tr) >> 1;
  if (pos <= tm) {
    if (L[v] == 0 || L[v] == L[id]) L[v] = ++lst;
    if (R[v] == 0) R[v] = R[id];
    upd(pos, L[v], L[id], tl, tm);
  } else {
    if (L[v] == 0) L[v] = L[id];
    if (R[v] == 0 || R[v] == R[id]) R[v] = ++lst;
    upd(pos, R[v], R[id], tm + 1, tr);
  }
  seg[v] = up(seg[L[v]], seg[R[v]], tl, tr, tm);
}
node qu(long long l, long long r, long long v, long long tl = 1,
        long long tr = n) {
  if (tl == l && tr == r) return seg[v];
  long long tm = (tl + tr) >> 1;
  if (r <= tm) return qu(l, r, L[v], tl, tm);
  if (l >= tm + 1) return qu(l, r, R[v], tm + 1, tr);
  return up(qu(l, tm, L[v], tl, tm), qu(tm + 1, r, R[v], tm + 1, tr), l, r, tm);
}
long long a[maxn], rmp[maxn];
vector<long long> ve, X[maxn];
long long mp(long long x) {
  return upper_bound(ve.begin(), ve.end(), x) - ve.begin();
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    ve.push_back(a[i]);
  }
  sort(ve.begin(), ve.end());
  ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
  long long LST = 0;
  for (auto x : ve) rmp[++LST] = x;
  for (long long i = 1; i <= n; i++) {
    a[i] = mp(a[i]);
    X[a[i]].push_back(i);
  }
  root[(long long)ve.size() + 1] = 1;
  build();
  for (long long i = (long long)ve.size(); i >= 1; i--) {
    root[i] = ++lst;
    for (auto x : X[i]) {
      upd(x, root[i], root[i + 1]);
    }
  }
  cin >> q;
  for (long long i = 1, l, r, w; i <= q; i++) {
    cin >> l >> r >> w;
    long long hi = (long long)ve.size() + 1, lo = 0;
    while (hi - lo > 1) {
      long long mid = (hi + lo) >> 1;
      long long XX = qu(l, r, root[mid]).ans;
      if (XX >= w)
        lo = mid;
      else
        hi = mid;
    }
    cout << rmp[lo] << "\n";
  }
}
