#1416. City Upgrading

City Upgrading

The city where crazyzhk resides is structured as a tree. On a certain day, the city’s network needs to be upgraded. To achieve this goal, routers need to be deployed. Each router covers the node it is placed on and its neighboring nodes. There is a cost aia_i associated with placing a router at each node. The question is: How can the routers be deployed at minimum cost to ensure that every node is covered?

Input

The input consists of multiple test cases. The first line contains a single integer tt(1t10001 \le t \le 1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a integer nn (1n1051 \le n \le 10^5) — the number of the vertices in the given tree.

The second line of each case are nn integers aia_i(1ai1051 \le a_i \le 10^5),denoting the cost of setting up a router at each node.

Each of the next n1n − 1 lines contains two integers uu and vv (1u,vn,uv1 \le u, v \le n, u \ne v) meaning that there is an edge between vertices uu and vv in the tree.

The data guarantees that the sum of n will not exceed 21052 \cdot 10^5

Output

For each test case print a single integer —— the minimum cost to ensure that every node is covered

Example

2
7
13 20 1 20 6 9 8
1 2
1 3
2 4
2 5
3 6
5 7
4
1 17 13 4
1 2
1 3
3 4
27
5

Limitation

Time limit: 3 seconds

Memory limit: 128 megabytes