Task
You have a tree (a connected acyclic graph) of nodes indexed from to . Each node has an integer value assigned to it.
You are given queries, where each query consists of two integers and . Your task is to find the minimum value (greater than 1) that is not divisible by any of the assigned values on the path between and , including the values assigned to and .
Input
The first line contains one integer (), the number of nodes. The second line contains integers ().
Each of the following lines contains two integers and , meaning that there is an edge between and .
The next line contains one integer (), the number of queries. Each of the next lines contains two integers and , describing a query.
For tests worth points: and every node is connected to at most other nodes.
For tests worth points: .
For tests worth points: for each and every node is connected to at most other nodes.
For tests worth points: for each .
For tests worth points: All values are unique for and every node is connected to at most other nodes.
For tests worth points: All values are unique for .
For tests worth points: Every node is connected to at most other nodes.
For tests worth points: No additional limitations.
Output
For each query, you need to write a single line with an integer representing the answer to that query.
stdin
9
7 25 8 4 1000000 6 11 3 2
5 7
5 1
5 6
7 3
1 2
1 4
6 8
2 9
3
8 9
3 8
4 9
stdout
5
2
3
Notes
In the sample case:
- Node values on the path of the first query are , , , , , . The minimum integer not divisible by any of them is .
- Node values on the path of the second query are , , , , . The minimum integer not divisible by any of them is .
- Node values on the path of the third query are , , , . The minimum integer not divisible by any of them is .