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. 
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class SolverE {

	public static void main(String[] Args) throws NumberFormatException,
			IOException {
		new SolverE().Run();
	}

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

	public String nextToken() throws IOException {
		while (Stok == null || !Stok.hasMoreTokens()) {
			Stok = new StringTokenizer(br.readLine());
		}
		return Stok.nextToken();
	}

	public int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	class Node {
		
		int length=0;
		int pref=0, suff=0, result=0;
		Node left=null, right=null;
		
		public Node(){
			
		}
		
		public Node(Node nleft, Node nright){
			left=nleft;
			right=nright;
			length=nleft.length+nright.length;
			result=Math.max(nleft.result, nright.result);
			result=Math.max(result, nleft.suff+nright.pref);
			if (nleft.suff==nleft.length){
				pref=nleft.length+nright.pref;
			} else
				pref=nleft.pref;
			
			if (nright.suff==nright.length){
				suff=nright.length+nleft.suff;
			} else
				suff=nright.suff;
		}
		
		
	}
	
	class Pair implements Comparable<Pair>{
		
		int val;
		int pos;
		
		public Pair(int aval, int apos){
			val=aval;
			pos=apos;
		}

		@Override
		public int compareTo(Pair arg0) {
			return arg0.val-val;
		}
	}
	
	int n;
	Node[] root;
	Pair[] mas;
	
	Node build(int left, int right){
		Node result=null;
		if (left==right){
			result=new Node();
			result.length=1;
		} else {
			int mid=(left+right)>>1;
			result=new Node(build(left, mid), build(mid+1,right));
		}
		return result;
	}
	
	Node update(Node curNode, int left, int right, int pos){
		Node result=null;
		if (left==right){
			result=new Node();
			result.pref=1;
			result.suff=1;
			result.result=1;
			result.length=1;
		} else {
			int mid=(left+right)>>1;
			Node nleft=curNode.left;
			Node nright=curNode.right;
			if (pos<=mid)
				nleft=update(nleft, left, mid, pos);
			else
				nright=update(nright, mid+1, right, pos);
			result=new Node(nleft, nright);
		}
		return result;
	}
	
	Node get(Node curNode, int curL, int curR, int left, int right){
		Node result=null;
		if (left>right){
			return new Node();
		}
		if (curL==left && curR==right)
			return curNode;
		
		int mid=(curL+curR)>>1;
		Node nleft=get(curNode.left,curL,mid,left,Math.min(right, mid));
		Node nright=get(curNode.right,mid+1,curR,Math.max(left, mid+1),right);
		return new Node(nleft, nright);
	}
	
	public void Run() throws NumberFormatException, IOException {
		//br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
		br=new BufferedReader(new InputStreamReader(System.in));  pw=new PrintWriter(new OutputStreamWriter(System.out));
		
		n=nextInt();
		mas=new Pair[n];
		for (int i=0; i<n; i++){
			mas[i]=new Pair(nextInt(), i);
		}
		Arrays.sort(mas);
		root=new Node[n+1];
		root[0]=build(0,n-1);
		for (int i=0; i<n; i++){
			root[i+1]=update(root[i],0,n-1,mas[i].pos);
		}
		
		int kolQuery=nextInt();
		for (int i=0; i<kolQuery; i++){
			int l=nextInt()-1;
			int r=nextInt()-1;
			int wid=nextInt();
			
			int min=0;
			int max=n;
			while (max-min>1){
				int mid=(max+min)>>1;
				Node node=get(root[mid], 0, n-1, l, r);
				if (node.result>=wid)
					max=mid;
				else
					min=mid;
			}
			pw.println(mas[max-1].val);
		}
		pw.flush();
		pw.close();
	}

}
