In Search of Gold

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

Sunset got a map of 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 a_ia\_i and b_ib\_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.

입력

The first line contains a single integer TT (1T10,0001 \leq T \leq 10\\,000), the number of test cases. For each test case:

The first line contains two integers nn and kk (2n20,0002 \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 u_iu\_i, v_iv\_i, a_ia\_i, b_ib\_i (1u_i,v_in1\leq u\_i,v\_i\leq n, u_iv_iu\_i\neq v\_i, 1a_i,b_i1091\leq a\_i,b\_i\leq 10^9) denoting a bidirectional tunnel between the u_iu\_i-th room and the v_iv\_i-th room, the length of which is either a_ia\_i or b_ib\_i.

It is guaranteed that the sum of all nn is at most 200,000200\\,000.

출력

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