#P7780. In Search of Gold

In Search of Gold

In Search of Gold

Problem Description

Sunset got a map about an abandoned gold mine in the border town. The map shows that the gold mine consists of nn rooms connected by n1n-1 bidirectional tunnels, forming a tree structure. The map is so strange that on the ii-th tunnel, there are two numbers aia_i and bib_i. The only thing Sunset knows is that there are exactly kk tunnels whose lengths are taken from aa while the lengths of other nk1n-k-1 tunnels are taken from bb. Tomorrow Sunset will explore that gold mine. He is afraid of getting lost in the gold mine, so can you please tell him the diameter of the gold mine if he is lucky enough? In other words, please calculate the minimum possible length of the diameter from the information Sunset has.

Input

The first line of the input contains a single integer TT (1T100001 \leq T \leq 10\,000), the number of test cases. For each case, the first line of the input contains two integers nn and kk (2n200002 \leq n \leq 20\,000, 0kn10\leq k\leq n-1, k20k\leq 20), denoting the number of rooms and the parameter kk. Each of the following n1n-1 lines contains four integers ui,vi,aiu_i,v_i,a_i and bib_i (1ui,vin1\leq u_i,v_i\leq n, uiviu_i\neq v_i, 1ai,bi1091\leq a_i,b_i\leq 10^9), denoting an bidirectional tunnel between the uiu_i-th room and the viv_i-th room, the length of which is either aia_i or bib_i. It is guaranteed that the sum of all nn is at most 200000200\,000.

Output

For each test case, output a single line containing an integer, the minimum possible length of the diameter.

Sample Input

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

Sample Output

6

Source

2020 Multi-University Training Contest 2