# Floyd - Warshall + Transitive closure

# Bones`s Battery

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

Starts with a line with the number of test cases **t** (**1** ≤ **t** ≤ **50**). 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 `u`

, _{i}`v`

and _{i}`d`

(_{i}**0** ≤ `u`

, _{i}`v`

< _{i}**n**, `u`

≠ _{i}`v`

, _{i}**1** ≤ `d`

≤ _{i}`10`

) indicating that road ^{9}**i** connects schools `u`

and _{i}`v`

(_{i}**0**-indexed) bidirectionally with distance `d`

._{i}

#### Output

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