Delta Quadrant
Much of the Delta Quadrant remains unexplored, but it is known that there are many dangerous regions inhabited by warring races. Yet, there is a small number of declared neutral zones that reach from planet to planet in which it is safe to travel.
A critical summit is planned, but it is on hold until a quorum of its members is attained. To reach this quorum, almost all of the delegates from the Delta Quadrant must be fetched and brought to the same location, where the Enterprise can pick them up for the summit.
The Enterprise is on its way to the Delta Quadrant. You must find the fastest way, using a single ship leaving from any one of the planets in the Delta Quadrant and returning to that same planet, to visit all but a given number of planets.
There are n planets and n - 1 safe paths through neutral zones connecting the planets. Each path has a known time duration required for traversal. Find the shortest time required, starting from an arbitrary planet, to visit n - k planets, and return.
Input
The first line contains the number of problems t (1 ≤ t ≤ 50). Each problem instance starts with a line with two integers: the number of planets n (2 ≤ n ≤ 10000) and the count of planets k (0 ≤ k ≤ min(n - 1, 20)) that need not be visited. Following that are n - 1 lines, each containing three integers, which are, in order, the source and destination planet numbers (from 0 to n - 1) and then the time required to traverse that path. The time is between 0 and 1000000, inclusive. The input graph will be connected.
Output
For each problem instance, print a single integer representing the shortest time of travel required.