Inaho was thinking of a tree problem, when he came up with this rather beautiful problem!
Given a tree originally rooted at containing nodes each with a value and an arbitrary value , support of the following operations:
1 R
Reroot the tree so that node is the root.2 a b
Print the highest common ancestor of nodes and .3 a b
Print the sum of all nodes' on the path from to , inclusive.4 a b
Print the product of all nodes' on the path from to , inclusive, modulo .5 a b
Print the minimum of all nodes' on the path from to , inclusive.6 a b
Print the maximum of all nodes' on the path from to , inclusive.7 a b
Print the greatest common divisor of all nodes' on the path from to , inclusive.8 a b
Print the bitwise AND of all nodes' on the path from to , inclusive.9 a b
Print the bitwise OR of all nodes' on the path from to , inclusive.10 a b
Print the bitwise XOR of all nodes' on the path from to , inclusive.11 a b
Print the number of nodes whose on the path from to , inclusive.12 a b
Print the number of nodes whose on the path from to , inclusive.13 a b
Print the value that minimizes , and of all nodes on the path from to , inclusive. Print if there is no such node where .14 a b
Print the value that minimizes , and of all nodes on the path from to , inclusive. Print if there is no such node where .
It is guaranteed .
Input Specification
The first line will contain three space-separated integers, , the number of nodes, the number of operations, and the arbitrary value , respectively.
The second line will contain space-separated integers, , the values of each node.
The next lines will each contain two space-separated integers, , indicating that nodes and are connected by an edge. It is guaranteed the entire tree is connected.
The next lines will each contain a valid operation as defined above.
Output Specification
For each operation that requires something to be outputted (everything except operation ), print the answer on its own line.
Sample Input
6 15 3
4 10 2 2 5 1
1 2
1 3
3 4
3 5
3 6
2 1 2
1 3
2 1 2
3 2 5
4 4 1
5 1 6
6 3 5
7 2 3
8 3 4
9 5 3
10 6 2
11 2 6
12 3 1
13 4 5
14 1 2
Sample Output
1
3
21
16
1
5
2
2
7
13
2
1
5
3
Comments