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;
template <typename T>
T gcd(T a, T b) {
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <class _T>
inline _T sqr(const _T &first) {
  return first * first;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const double EPS = 1e-9;
char TEMPORARY_CHAR;
const int INF = 1e9;
inline void input(int &a) {
  a = 0;
  while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') &&
         (TEMPORARY_CHAR != '-')) {
  }
  char neg = 0;
  if (TEMPORARY_CHAR == '-') {
    neg = 1;
    TEMPORARY_CHAR = getchar();
  }
  while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {
    a = 10 * a + TEMPORARY_CHAR - '0';
    TEMPORARY_CHAR = getchar();
  }
  if (neg) a = -a;
}
inline void out(long long a) {
  if (!a) putchar('0');
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  char s[20];
  int i;
  for (i = 0; a; ++i) {
    s[i] = '0' + a % 10;
    a /= 10;
  }
  for (int j = (i)-1; j >= 0; j--) putchar(s[j]);
}
inline int nxt() {
  int(ret);
  input((ret));
  ;
  return ret;
}
struct data {
  int l;
  int r;
  int mid;
  int len;
};
void merge(const data &l, const data &r, data &res) {
  res.len = l.len + r.len;
  res.mid = 0;
  ((res.mid) = (l.mid) > (res.mid) ? (l.mid) : (res.mid));
  ((res.mid) = (r.mid) > (res.mid) ? (r.mid) : (res.mid));
  ((res.mid) = (l.r + r.l) > (res.mid) ? (l.r + r.l) : (res.mid));
  if (l.len == l.l) {
    res.l = l.l + r.l;
  } else {
    res.l = l.l;
  }
  if (r.len == r.r) {
    res.r = r.r + l.r;
  } else {
    res.r = r.r;
  }
}
struct node {
  data info;
  int val;
  node *l, *r;
  node(int v) {
    val = v;
    info = data{v, v, v, 1};
  }
  node(node *a, node *b) {
    merge(a->info, b->info, info);
    l = a, r = b;
  }
};
node *build(int tl, int tr) {
  if (tr - tl == 1) {
    return new node(0);
  }
  int tm = (tl + tr) / 2;
  return new node(build(tl, tm), build(tm, tr));
}
node *update(node *v, int tl, int tr, int pos, int val) {
  if (tr - tl == 1) {
    return new node(val);
  }
  int tm = (tl + tr) / 2;
  if (pos < tm) {
    return new node(update(v->l, tl, tm, pos, val), v->r);
  } else {
    return new node(v->l, update(v->r, tm, tr, pos, val));
  }
}
data get(node *v, int tl, int tr, int l, int r) {
  if (l >= r) return data{0, 0, 0, 0};
  if (tl == l && tr == r) {
    return v->info;
  }
  int tm = (tl + tr) / 2;
  data res;
  merge(get(v->l, tl, tm, l, min(tm, r)), get(v->r, tm, tr, max(tm, l), r),
        res);
  return res;
}
void print(node *v, int tl, int tr) {
  if (tr - tl == 1) {
    cout << v->val << " ";
    return;
  }
  int tm = (tl + tr) / 2;
  print(v->l, tl, tm);
  print(v->r, tm, tr);
}
int main() {
  srand(33);
  int(n);
  input((n));
  ;
  int h[n];
  int id[n];
  for (int i = 0; i < n; ++i) {
    h[i] = nxt();
    id[i] = i;
  }
  node *st[n + 1];
  st[0] = build(0, n);
  sort(id, id + n, [&](int a, int b) { return h[a] > h[b]; });
  for (int i = 0; i < n; ++i) {
    int cur = id[i];
    st[i + 1] = update(st[i], 0, n, cur, 1);
  }
  int(q);
  input((q));
  ;
  while (q--) {
    int(l);
    input((l));
    ;
    int(r);
    input((r));
    ;
    --l;
    int(w);
    input((w));
    ;
    int lo = 0, hi = n - 1;
    while (lo < hi) {
      int mid = (lo + hi) >> 1;
      data res = get(st[mid + 1], 0, n, l, r);
      if (res.mid < w) {
        lo = mid + 1;
      } else {
        hi = mid;
      }
    }
    cout << h[id[lo]] << "\n";
  }
  return 0;
}
