Alice has N integers a1 , a2 , .... , an−1 , an . An integer may occur multiple times in the array.
Alice has to answer Q queries, each query consisits of two integers x and y. Alice need to find the maximum value of |i−j| such that ai=x and ai=y. Help Alice answer the Q queries.
INPUT:
The first line contains a single integer N.
The second line contains N space separated integers.
The third line contains a single integer Q.
Q lines follow, each line contains two space sepatated integers x and y.
OUTPUT:
Output Q lines, ith of which line should contain a single integer max|i−j| associated with ith query if both x and y are in the array. If either of x or y is not present in the array output -1.
CONSTRAINTS:
2≤N≤200000
0≤ai≤109 for all i from 1 to N