Alice has integers , , .... , , . An integer may occur multiple times in the array.
Alice has to answer queries, each query consisits of two integers and . Alice need to find the maximum value of such that and . Help Alice answer the queries.
INPUT:
The first line contains a single integer .
The second line contains space separated integers.
The third line contains a single integer .
lines follow, each line contains two space sepatated integers and .
OUTPUT:
Output lines, of which line should contain a single integer associated with query if both and are in the array. If either of or is not present in the array output -1.
CONSTRAINTS:
for all i from to