Tobby on Tree

Do you remember Tobby? He is a very cute dog who lives in tobbyland. Tobby lives in a city where any two houses are connected by exactly one path, and that path is bidirectional. All the houses are identified by an integer 0 ≤ id < N , and have another integer indicating its corresponding value. Tobby found on internet an interesting game called, “the subtraction game” that goes as follow: Given a sequence of N elements: a0, a1, ..., an−1: If all the numbers are equal, the game ends. Otherwise Select two numbers which are unequal Subtract the smaller number from the larger number Replace the larger number with the result from above. The game always ends and no matter how you play, it will always terminate on the same value. The result of the game is that value. The game is so cool for Tobby that he decides to play it as much as possible. For this reason each day Tobby visits two friends who live in the houses u and v and records all the values of the houses in the path from u to v (inclusive). At the end of the day he plays the substraction game with the sequence that he wrote. The value of a house can change sometimes, but Tobby will always know the new value. In order to help Tobby, he asks to answer the following types of queries:

  1. given u, v: Find the result of the subtraction game on the path from u to v (inclusive). 2. given u, x: Change the value of the house u by x. Input The input has several test cases. The first line contains an integer N ≤ 50000, the number of houses. The next line contains N integers, the i-th number is the value of the i-th house 1 ≤ value ≤ 10000. The next N − 1 lines contain two integers 0 ≤ u, v ≤ N − 1 indicating a connection between the houses u and v. The next line contains an integer 1 ≤ q ≤ 10000 followed by q lines each containing a query. The first number of each of those lines is the query type and the rest of the line contains the query parameters. Output For each query of type 1, print the result of the subtraction game in the path from u to v. Sample Input 5 5 15 20 15 9 02 03 31

2/2 34 3 121 233 114 Sample Output 5 3