- Time limit: 3.00 s
- Memory limit: 512 MB
You are given a sequence consisting of positive integers. You have to answer queries. A query is defined by a triplet of numbers . For each query, you have to find the largest such that and is coprime with , or determine that there is no such .
Two numbers are coprime if the only positive integer that divides both of them is 1.
Input
The first line of the input contains two integers and .
The second line contains integers .
The next lines contain queries. The -th of these lines contains three integers , and .
Output
For each query, output the largest such if it exists. Otherwise output -1
.
Constraints
Example
Input:
5 4 1 2 3 4 6 1 5 2 1 1 1 4 5 2 3 5 3
Output:
3 1 -1 4