#P7815. Tree

Tree

Tree

Problem Description

Aphelios likes to play with tree. A weighted tree is an undirected connected graph without cycles and each edge has a weight. The degree of each vertex is the number of vertexes which connect with it. Now Aphelios has a weighted tree TT with nn vertex and an integer kk, and now he wants to find a subgraph GG of the tree, which satisfies the following conditions: 11. GG should be a connected graph, in other words, each vertex can reach any other vertex in the subgraph GG. 22. the number of the vertex whose degree is larger than kk is no more than 11. 33. the total weight of the subgraph is as large as possiblie . Now output the maximum total weight of the subgraph you can find.

Input

The first line contains an integer qq, which represents the number of test cases. For each test case, the first line contains two integer nn and kk (1n2×105,0k<n)(1\leq n\leq 2 \times 10^{5},0\leq k<n). For next n1n-1 lines , each line contains 33 numbers u,v,du,v,d, which means that there is an edge between uu and vv weighted dd (1u,vn,0d109)(1\leq u,v\leq n,0\leq d \leq 10^{9}). You may assume that n106\sum n \leq 10^{6}.

Output

For each test case, output one line containing a single integer ansans denoting the total weight of the subgraph.

Sample Input

1
5 2
1 2 5
2 3 2
2 4 3
2 5 4

Sample Output

14

Source

2020 Multi-University Training Contest 5