#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 denotes the number of test case.
For each test case,
In the first line, you will get two number () and (), denotes the number of towns and the number of roads.
The next lines, each contains three number ,,, denotes there is a road between and that needed () 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