# The Minimum Game solution codechef starters 12

Alice and Bob have invented a new game. They have a rooted tree having  nodes (rooted at node ), and the  node has the value  associated with it (-indexed). The value associated with the root node is .

They start with a marker at the root node, and a score of . Alice and Bob moves alternatively, with Alice moving first. In one move, they can move the pointer from a node to one of its child node, and add the value associated with that child node to the score. If the marker reaches a leaf node, the game ends.

Alice wants to minimize the score of the game, whereas Bob wants to maximize the score. They were about to start the game when the Charlie arrives. He looked at the game, and declared the game to be boring. However, Charlie asked them – “What will be the score at the end of the game, if  one of you can skip   moves?”

Can you help Alice and Bob to answer Charlie?

### Input Format

• The first line of input contains a single integer , denoting the number of testcases. The description of the  testcases follows.
• The first line of each test case contains two space separated integers  and .
• The second line of each test case contains  space separated integers . It is guaranteed that .
• The following  lines contains two space separated integers  and , which denotes that there is an edge between nodes  and .

### Output Format

For each testcase, output in a single line the answer to the Charlie’s problem.

### Constraints

• The sum of  over all test cases does not exceed

### Sample Input 1

3
3 1
0 1 2
1 2
1 3
4 0
0 1 2 3
1 2
1 3
2 4
7 0
0 2 1 4 2 7 3
1 2
1 3
2 4
2 5
3 6
3 7


### Sample Output 1

1
2
6


### Explanation

Test Case : Alice can move the marker to node , and hence making score . If Alice skips her chance, then Bob can move the marker to node , and hence making score = . Therefore, Alice will not skip her chance.

Test Case : If Alice moves the marker to node , then Bob will move the marker to node , making score = . If Alice moves the marker to node , the game will end, and the score will be .