시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 128 MB 23 9 8 38.095%

문제

Bones is investigating what electric shuttle is appropriate for his mom’s school district vehicle. Each school has a charging station. It is important that a trip from one school to any other be completed with no more than K rechargings. The car is initially at zero battery and must always be recharged at the start of each trip; this counts as one of the K rechargings. There is at most one road between each pair of schools, and there is at least one path of roads connecting each pair of schools. Given the layout of these roads and K, compute the necessary range required of the electric shuttle.

입력

Input begins with a line with one integer T (1 ≤ T ≤ 50) denoting the number of test cases. Each test case begins with a line containing three integers N, K, and M (2 ≤ N ≤ 100, 1 ≤ K ≤ 100), where N denotes the number of schools, K denotes the maximum number of rechargings permitted per trip, and M denotes the number of roads. Next follow M lines each with three integers ui, vi, and di (0 ≤ ui, vi < N, ui ≠ vi, 1 ≤ di ≤ 109) indicating that road i connects schools ui and vi (0-indexed) bidirectionally with distance di.

출력

For each test case, output one line containing the minimum range required.

예제 입력

2
4 2 4
0 1 100
1 2 200
2 3 300
3 0 400
10 2 15
0 1 113
1 2 314
2 3 271
3 4 141
4 0 173
5 7 235
7 9 979
9 6 402
6 8 431
8 5 462
0 5 411
1 6 855
2 7 921
3 8 355
4 9 113

예제 출력

300
688

힌트