#Lutece0145. Earthquake

Earthquake

Migrated from Lutece 145 Earthquake

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

After the big earthquake, a lot of roads have been destroyed, some towns are disconnected with each other.

In order to save the trapped as soon as possible, we need to try our best to rebuild the roads, and make sure all the towns will be reconnected(that is any villages is connected to the others with a clear route at least).

Unfortunately, we have only one team to rebuild the roads. Now,please tell us how long do you think these roads can be reconnected.

Input

The first line contains a number TT denotes the number of test case.

For each test case,

In the first line, you will get two number NN (1N10001\leq N\leq 1000) and MM(1MN×N1\leq M\leq N\times N), denotes the number of towns and the number of roads.

The next MM lines, each contains three number AA,BB,CC, denotes there is a road between AA and BB that needed CC (1C10001\le C\le 1000) minutes to rebuild.

Output

For each test case, you should output a line contains a number denotes the minimal time need to rebuild the roads so that all the towns are connected.

Samples

2
3 3
1 2 3
2 3 3
3 1 7
3 3
1 2 3
2 3 3
3 1 1
6
4

Resources

Sichuan State Programming Contest 2008