


1. DIST[i][j] = DIST[j][i].
2. DIST[i][i] = 0.
Consider that there are 4 cities i.e. ‘N’ = 4, and the distance between each pair of cities is given by the following matrix ‘DIST’:
[0, 10, 7, 6]
[10, 0, 8, 5]
[7, 8, 0, 12]
[6, 5, 12, 0]
Graphically, cities can be represented as -:

Assume Ninjas wants to install a server in 2 cities i.e ‘K’ = 2. Then one optimal choice is to select cities 2 and 3.
After that, the minimum distance of city 0 from the server is 6 (i.e from city 2).
The minimum distance of city 1 from the server is 5 (i.e from city 3).
The minimum distance of cities 2 and 3 from the server is 0, as the server is installed in these cities.
Thus the maximum distance of the city from the server is max (6, 5, 0, 0) = 6.
So, we should return 6.
No selection of two cities can give a maximum distance which is less than 6.
The first line of input contains an integer ‘T’ denoting the number of test cases. then ‘T’ test cases follow.
The first line of each test case consists of two single space-separated integers ‘N’ and ‘K’ respectively representing the number of cities in Ninja Land and the number of cities where the server needs to be installed.
The next ‘N’ line follows in each test case. Each of these ‘N’ lines consists of ’N’ single space-separated integers. These ‘N’ lines together represent the matrix ‘DIST’.
For each test case, print a single integer that represents the maximum distance of a city from the server when ‘K’ cities are selected optimally.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= N <= 15
1 <= K <= N
1 <= DIST[i][j] <= 10^9, for i != j
DIST[i][j] = 0, for i = j
Time limit: 1 sec
This problem is an NP-Hard problem i.e there exists no polynomial-time solution for it. So we cannot do anything more than brute force for the exact solution.