Bones's Battery

No attempts yetTime limit5sMemory limit128 MB

Problem

Bones is shopping for an electric shuttle for the school district where his mother works. Every school has a charging station. Call the range of the shuttle the greatest distance it can drive on a full charge.

A trip from any school to any other school has to finish with at most KK rechargings. The shuttle's battery starts out empty, so it must be charged before it sets off, and that charge counts toward the KK. It may be charged again at any school it stops at along the way.

At most one road runs between any pair of schools, and every pair of schools is joined by some sequence of roads. Given the road network and KK, find the smallest range the electric shuttle needs.

Input

The first line has one integer TT (1T501 \le T \le 50), the number of test cases.

Each test case begins with a line of three integers NN, KK, and MM (2N1002 \le N \le 100, 1K1001 \le K \le 100), where NN is the number of schools, KK is the largest number of rechargings allowed on one trip, and MM is the number of roads.

Each of the next MM lines has three integers uiu_i, viv_i, and did_i (0ui,vi<N0 \le u_i, v_i < N, uiviu_i \ne v_i, 1di1091 \le d_i \le 10^9). Road ii joins school uiu_i and school viv_i in both directions and has length did_i. Schools are numbered from 0.

Output

For each test case, print the smallest required range on one line.