Mario and the Evil Toad

Pick K distinct non-root nodes of a weighted tree and order them to maximize the round trip from the root through them in order.

Medium7Dynamic programmingTreeCombinatoricsNo attempts yetTime limit3sMemory limit256 MB

Problem

Mario runs from castle to castle to rescue Princess Peach from the evil Bowser. No matter which stage he clears, a small mushroom person (a Toad) only tells him that the princess is in another castle. Mario suspects that this Toad is evil and wants to send him to the farthest castle just for fun.

Mario's world is a tree with NN nodes. It has N1N-1 edges, it is connected, and the nodes are numbered from 11 to NN. Each node holds one castle, and each edge is one stage. Passing a stage takes a time that is fixed per edge and is the same in both directions.

The Toad picks KK distinct castles and never picks castle 11, the root. Mario must visit the picked castles in the given order. His trip starts at castle 11 and ends at castle 11. He always moves along a shortest path when he travels from one castle to the next, and he may pass the same node or edge several times.

The Toad chooses both the KK castles and their order. Find the longest time Mario's trip can take.

Input

The first line has the number of test cases TT. (1T1001 \le T \le 100)

The first line of each test case has two integers NN and KK. (2N10002 \le N \le 1000, 1K1001 \le K \le 100, 1KN11 \le K \le N-1) NN is the number of castles and KK is the number of castles the Toad picks.

The next N1N-1 lines describe nodes 22 through NN in that order. Each line has two integers PiP_i and CiC_i (1PiN1 \le P_i \le N, 0Ci1000000 \le C_i \le 100000): the number of that node's parent, and the time needed to pass the stage between the node and its parent.

The root is always node 11, and the N1N-1 edges always form a tree rooted at node 11. A parent may have a larger number than its child.

Output

For each test case print one line in the form Case n: followed by the answer. nn is the number of the test case and starts at 11.

Hint

In the third test case of the example the Toad can pick castles 55, 22, 44 in this order to reach the maximum. The order 44, 22, 55 gives the same value.