// Arup Guha
// 7/23/2025
// Solution? to Kattis Problem Island Hopping
// https://open.kattis.com/problems/islandhopping
// Illustrates Prim's Algorithm

import java.util.*;

public class islandhopping {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			// Read in pts.
			int n = stdin.nextInt();
			double[][] pts = new double[n][2];
			for (int i=0; i<n; i++) {
				pts[i][0] = stdin.nextDouble();
				pts[i][1] = stdin.nextDouble();
			}
			
			ArrayList<edge>[] edges = new ArrayList[n];
			
			// Create the graph.
			for (int i=0; i<n; i++) {
				edges[i] = new ArrayList<edge>();
				
				for (int j=0; j<n; j++) {
					double w = Math.sqrt( (pts[i][0]-pts[j][0])*(pts[i][0]-pts[j][0]) + 
										  (pts[i][1]-pts[j][1])*(pts[i][1]-pts[j][1]) );
					if (i == j) continue;
					edges[i].add(new edge(i, j, w));
				}
			}
			
			// Run Prim's.
			double res = prims(edges,0);
			
			// Ta da!
			System.out.println(res);
		}
	}
	
	// Run's Prim's starting at v.
	public static double prims(ArrayList<edge>[] edges, int v) {
	
		int numE = 0, n = edges.length;
		double mst = 0;
		
		// Mark vertices connected in the tree we are growing.
		boolean[] used = new boolean[n];
		used[v] = true;
		
		// Add all edges incident to v into our priority queue.
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		for (edge x: edges[v])
			pq.add(x);
		
		// Run until we complete it or there's no mst.
		while (pq.size() > 0 && numE < n-1) {
		
			// Get the next edge.
			edge cur = pq.poll();
			
			// This doesn't get us anywhere new.
			if (used[cur.u] && used[cur.v]) continue;
			
			// Assign newv to the vertex that wasn't previously connected.
			int newv = used[cur.u] ? cur.v : cur.u;
			
			// Update all variables to account for the new edge.
			used[newv] = true;
			mst += cur.w;
			numE++;
			
			// Now add all edges incident to newv to the priority queue.
			for (edge x: edges[newv])
				pq.add(x);
		}
		
		// Returns the weight of the mst or -1 if none edges.
		return numE == n-1 ? mst : -1;
	}
}

class edge implements Comparable<edge> {

	public int u;
	public int v;
	public double w;
	
	public edge(int myu, int myv, double myw) {
		u = myu;
		v = myv;
		w = myw;
	}	
	
	public int compareTo(edge other) {
		if (this.w < other.w) return -1;
		if (other.w < this.w) return 1;
		if (this.u != other.u) return this.u - other.u;
		return this.v - other.v;
	}
}