# Square Root Decomposition

hard

You are given a list of N numbers and Q queries.Each query is specified by two numbers i and j.The answer to each query is the minimum number between the range between i and j(including i and j).The query are specified using 0 based indexing. Expected complexity : O(Q * logN)

## Constraints

1<= N <= 10^6 1 <= Q <= 10^5 0 <= i,j <= N-1

## Format

### Input

The first line contains N. The next line holds N numbers. Following the list is a number Q. The next Q lines each contain two numbers i and j which specify a query you must answer.

### Output

For each query, output the Minimum in the range in a line.

## Example

Sample Input

4
2 4 3 1
4
1 2
1 3
2 2
0 1

### Sample Output

3
1
3
2

Question Video