// Arup Guha
// 3/30/2024
// Solution to Kattis Problem: Island Hopping (for Junior Knights Prim's Lecture)
// https://open.kattis.com/problems/islandhopping

import java.util.*;

public class islandhopping {

	public static int n;
	public static ArrayList<edge>[] graph;
	public static double[] x;
	public static double[] y;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=0; loop<nC; loop++) {
		
			n = stdin.nextInt();
			x = new double[n];
			y = new double[n];
			for (int i=0; i<n; i++) {
				x[i] = stdin.nextDouble();
				y[i] = stdin.nextDouble();
			}
			
			// Form the graph.
			graph = new ArrayList[n];
			for (int i=0; i<n; i++) {
				graph[i] = new ArrayList<edge>();
			
				// Add all edges.
				for (int j=0; j<n; j++) {
					if (i == j) continue;
					
					// This is our new edge.
					graph[i].add(new edge(i, j, dist(i, j)));
				}
			}
			
			// Ta da!
			System.out.println(prims(0));
		}
	}
	
	// Runs Prim's from vertex startv and returns the weight of the minimum spanning tree of graph.
	public static double prims(int startv) {
		
		boolean[] used = new boolean[n];
		used[startv] = true;
		int numedges = 0;
		double res = 0;
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		
		// Add each edge from the start vertex into the priority queue.
		for (edge e: graph[startv])
			pq.offer(e);
		
		// Loop until we have enough edges.
		while (numedges < n-1) {
			
			// Graph isn't connected.
			if (pq.size() == 0) break;
			
			// Get the next edge.
			edge cur = pq.poll();
			
			// Doesn't get us somewhere new, try again.
			if (used[cur.u] && used[cur.v]) continue;
			
			// Figure out new edge.
			int newv = used[cur.v] ? cur.u : cur.v;
			
			// Mark as true.
			used[newv] = true;
			
			// Add edges leaving newv to the priority queue.
			for (edge e: graph[newv])
				pq.offer(e);
			
			// Update edge count and mst result.
			numedges++;
			res += cur.w;
		}
		
		// Means no mst.
		if (numedges < n-1) return -1;
		
		// This is the mst weight.
		return res;
	}
	
	// Returns the distance btw. pts i and j.
	public static double dist(int i, int j) {
		return Math.sqrt( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
	}
}

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) {
		return Double.compare(this.w,other.w);
	}

}