// Arup Guha
// 10/8/2015
// Kruskal'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_kruskals {

    public static void main(String[] args) {

        Scanner stdin = new Scanner(System.in);
        int numCases = stdin.nextInt();

        for (int loop=1; loop<=numCases; loop++) {
            int v = stdin.nextInt();
            int e = stdin.nextInt();
            edge[] graph = new edge[e];

            // Read and store graph edges.
            for (int i=0; i<e; i++) {
                int v1 = stdin.nextInt()-1;
                int v2 = stdin.nextInt()-1;
                int w = stdin.nextInt();
                graph[i] = new edge(v1, v2, w);
            }

            // Output result.
			int res = kruskals.mst(graph, v);
			if (res == -1)
				System.out.println("Campus #"+loop+": I'm a programmer, not a miracle worker!");
			else
				System.out.println("Campus #"+loop+": "+res);
        }
    }
}

/*** Disjoint Set with Path Compression ***/
class dset {

	public int[] parent;
	public int n;

	public dset(int size) {
		parent = new int[size];
		for (int i=0; i<size; i++)
			parent[i] = i;
	}

	// Finds the root of v and then reattaches v directly to this root.
	// This is path compression.
	public int find(int v) {
		if (parent[v] == v) return v;
		return parent[v] = find(parent[v]);
	}

	// Unions the sets storing v1 and v2. Returns false if already together and true
	// if the operation was performed.
	public boolean union(int v1, int v2) {

		// Find roots.
		int p1 = find(v1);
		int p2 = find(v2);
		if (p1 == p2) return false;

		// If we get here we have to merge the trees.
		parent[p2] = p1;
		return true;
	}
}

/*** 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 kruskals {

	// We just give Kruskal's a list of all edges.
	public static int mst(edge[] list, int n) {
		
		// This is the greedy part.
		Arrays.sort(list);

		dset trees = new dset(n);
		int numEdges = 0, res = 0;

		// Consider edges in order.
		for (int i=0; i<list.length; i++) {

			// Try to put together these two trees.
			boolean merged = trees.union(list[i].v1, list[i].v2);
			if (!merged) continue;

			// Bookkeepping.
			numEdges++;
			res += list[i].w;
			if (numEdges == n-1) break;
		}

		// -1 indicates no MST, so not connected.
		return numEdges == n-1 ? res : -1;
	}
}
