9065 - Minimum Spanning Tree   

Description

Given an undirected weighted graph G = (V, E, W), output the weight of its minimum spanning tree.

Input

The input includes multiple test cases. The first of the input is an integer T (T <= 1000) specifying the number of test cases. For each case, the first line contains two integers: the number of the node n (2 <= n <= 1000) and the number of the edges m(1<=m<=100000). In the following m lines, each line contains three integers (si, ei, ci), 1<=si, ei<=n, 1<= ci<=100, representing the indices of end vertices of an edge and the weight of the edge.

Output

For each case, output a line that indicates the weight of the minimum spanning tree of the graph.

Sample Input  Download

Sample Output  Download

Tags




Discuss