Quarantine Stations

Place K quarantine barriers on the edges of a weighted tree so that the largest connected component's total population is minimized.

Hard8TreeBinary searchDFSNo attempts yetTime limit3sMemory limit256 MB

Problem

There is a country where frail people live. It has NN cities and N1N-1 roads, each road joining two cities, and between any two cities there is exactly one route.

Every few years an epidemic spreads through the country and does heavy damage. To hold it back, the government picks KK of the N1N-1 roads and builds a quarantine station on each of them. An infected person cannot pass a road that has a quarantine station, so such a road becomes a barrier against the epidemic.

Quarantine stations alone cannot end the epidemic, so the government also stockpiles doses of a cure. Whoever is infected first, and in whichever city, every person who can catch the disease in that outbreak must receive one dose. Find the smallest stockpile that suffices when the KK quarantine stations are placed in the best possible way.

Input

The first line contains the number of test cases TT.

The first line of each test case contains the number of cities NN (2N1000002 \le N \le 100000) and the number of quarantine stations KK (1KN11 \le K \le N-1).

The second line contains NN positive integers. The ii-th of them, XiX_i (1Xi10000000001 \le X_i \le 1000000000), is the population of city ii.

Each of the next N1N-1 lines contains two integers AiA_i and BiB_i (1AiN1 \le A_i \le N, 1BiN1 \le B_i \le N), meaning that city AiA_i and city BiB_i are joined by a road.

Output

For each test case, print the smallest number of doses to stockpile on its own line.

Hint

In the first example, build quarantine stations on the road between city 3 and city 5 and on the road between city 4 and city 3. Then 11 doses are enough. An outbreak that starts in city 1 can infect the 10 people of cities 1 and 3, one that starts in city 2 can infect the 11 people of cities 2 and 4, one that starts in city 3 can infect 10 people, one that starts in city 4 can infect 11 people, and one that starts in city 5 can infect 5 people. In every case 11 doses cover everyone.