#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define REPSZ(i,v) REP(i,SZ(v))
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
typedef long long ll;
typedef pair<int,int> PII;

ll n;
vector<PII> adj[1000000];

void run() {
	scanf("%lld",&n);
	REP(i,n) adj[i].clear();
	REP(i,n-1) { int a,b,c; scanf("%d%d%d",&a,&b,&c); adj[a].PB(MP(b,c)); adj[b].PB(MP(a,c)); }

	ll res=0;
	REP(i,n) {
		vector<int> done(n,0); queue<PII> q;
		q.push(MP(i,0)); done[i]=1;
		while(!q.empty()) {
			int at=q.front().first,cur=q.front().second; q.pop();
			res+=cur;
			REPSZ(i,adj[at]) { int to=adj[at][i].first,len=adj[at][i].second; if(!done[to]) q.push(MP(to,cur+len)),done[to]=1; }
		}
	}
	
	printf("%.3lf\n",1.0*res/(n*(n-1)));
}

int main() {
	int n; scanf("%d",&n); FORE(i,1,n) run();
	return 0;
}
