import java.util.*;

public class erikjan {
	public static class Result {
		public int nrnodes;
		public long sumdist;
		
		public Result(int nrnodes, long sumdist) {
			this.nrnodes = nrnodes;
			this.sumdist = sumdist;
		}
	}
	
	public static class Edge {
		public Node a,b;
		public int len;
		
		public Edge(Node a,Node b,int len) {
			this.a = a;
			this.b = b;
			this.len = len;
			a.edges.add(this);
			b.edges.add(this);
		}
		
		public Node other(Node me) {
			if(me == a) return b;
			if(me == b) return a;
			throw new IllegalArgumentException("`me' must be one of the endpoints");
		}
	}
	
	public static class Node {
		public List<Edge> edges = new ArrayList<Edge>();
	}
	
	public static Result go(Node at, Edge prev, int n) {
		Result ret = new Result(1, 0);
		for(int i = 0; i < at.edges.size(); ++i) {
			Edge edge = at.edges.get(i);
			if(edge == prev) continue;
			Result cur = go(edge.other(at), edge, n);
			ret.nrnodes += cur.nrnodes;
			ret.sumdist += cur.sumdist;
			ret.sumdist += (long) (n - cur.nrnodes) * cur.nrnodes * edge.len;
		}
		return ret;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int nrcases = in.nextInt();
		for(int i = 1; i <= nrcases; ++i) {
			int n = in.nextInt();
			Node[] nodes = new Node[n];
			for(int j = 0; j < n; ++j) nodes[j] = new Node();
			for(int j = 0; j < n - 1; ++j) {
				Edge e = new Edge(nodes[in.nextInt()], nodes[in.nextInt()], in.nextInt());
			}
			long res = go(nodes[0], null, n).sumdist;
			System.out.printf(Locale.US,"%.3f\n",1.0*res/(n*(n-1)/2));
		}
	}
}
