SZUOJ-Problem(A60):Roads

Judge Info

  • Memory Limit: 32768KB
  • Case Time Limit: 10000MS
  • Time Limit: 10000MS
  • Judger: Number Only Judger

Description

Actually, Mr.K is a famous engineer. He got a big project resently.He is asked to build roads to connect several city. At first, there is no roads between any pair of these city. He is given the distances between any two cities . Mr.K wants to build roads as less length as posible to make all city connected.

Input

The input will contains multiple test cases. The first line of the input is a single integer  which is the number of test cases. T test cases follow.

Each test case contains one positive integers  --the number of the citis numbered 1 to n. Next,there are n rows, and which row contains n positive integer. The integer at ith row,jth column is the distance between city i and city j, and it will never bigger than 10,000;

Output

For each input test case, you are to output a single integer - the smallest length of roads that make all cities connected.

Sample Input

2


3
0 1 1
1 0 2
1 2 0 

3
0 1 1
1 0 2
1 2 0

Sample Output

2

你可能感兴趣的:(SZUOJ-Problem(A60):Roads)