// Arup Guha
// 10/8/2015
// Prim's Algorithm - written as an example for the programming team.
/*** Updated on 10/22/2026 for COP 3503 ***/
/*** Solution to 2014 UCF High School Problem Ant Tunneling ***/

import java.util.*;

public class ant_prims {

    public static void main(String[] args) {

        Scanner stdin = new Scanner(System.in);
        int numCases = stdin.nextInt();

        for (int loop=1; loop<=numCases; loop++) {
			
			// Store graph in regular way listing each vertices incident edges.
            int v = stdin.nextInt();
            int e = stdin.nextInt();
            ArrayList[] graph = new ArrayList[v];
            for (int i=0; i<v; i++)
                graph[i] = new ArrayList<edge>();

            // Read and stor graph edges.
            for (int i=0; i<e; i++) {
                int v1 = stdin.nextInt()-1;
                int v2 = stdin.nextInt()-1;
                int w = stdin.nextInt();
                graph[v1].add(new edge(v1, v2, w));
                graph[v2].add(new edge(v1, v2, w));
            }

            // Output result.
			int res = prims.mst(graph, 0);
			if (res == -1)
				System.out.println("Campus #"+loop+": I'm a programmer, not a miracle worker!");
			else
				System.out.println("Campus #"+loop+": "+res);
        }
    }
}

/*** Usual edge class. ***/
class edge implements Comparable<edge> {

	public int v1;
	public int v2;
	public int w;

	public edge(int a, int b, int weight) {
		v1 = a;
		v2 = b;
		w = weight;
	}

	public int compareTo(edge other) {
		return this.w - other.w;
	}
}

class prims {

	public static int mst(ArrayList[] graph, int v) {

		// Mark vertex v as being in mst.
		int n = graph.length;
		boolean[] used = new boolean[n];
		used[v] = true;

		// Add all of v's edges into the priority queue.
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		for (int i=0; i<graph[v].size(); i++)
			pq.offer( ((ArrayList<edge>)graph[v]).get(i));

		int numEdges = 0, res = 0;

		while (pq.size() > 0) {

			// Get next edge.
			edge next = pq.poll();
			if (used[next.v1] && used[next.v2]) continue;
			
			// Figure out the new vertex of the two.
			int nextV = used[next.v1] ? next.v2 : next.v1;

            // Add new items to priority queue - need to check which vertex is new.
			for (edge e: (ArrayList<edge>)graph[nextV])
				pq.offer(e);
            used[nextV] = true;

			// Bookkeeping
			numEdges++;
			res += next.w;
			if (numEdges == n-1) break;
		}

		// -1 indicates no MST, so not connected.
		return numEdges == n-1 ? res : -1;
	}
}
