Consider a tree with
nodes, rooted at node .
The value of the node is denoted by .
Chef defines the function as follows:
Let denote the set of all the values of nodes that lie in the shortest path from to (including both and ). Then, denotes the MEX of the set .
Find the maximum value of , where .
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of the test cases follows.
- The first line of each test case contains a single integer - the number of nodes in the tree.
- The second line of each test case contains space separated integers . represents the value of the node.
- The following lines contain two space-separated integers and , denoting that there exists an edge between the nodes and .
Output Format
For each test case, output in a single line, the maximum value of where .
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
3
3
0 1 2
1 2
1 3
4
0 1 2 3
1 2
2 3
1 4
5
1 2 3 4 0
1 2
2 3
2 4
1 5
Sample Output 1
2
3
2
Explanation
Test case :
- .
- .
Thus, the answer is .
Test case :
- .
- .
Thus, the answer is .
Test case :
- .
- .
- .
Thus, the answer is .
ConversionConversion EmoticonEmoticon