#include <cstdio>
#include <vector>
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<vector<PII> > adj;

void run() {
	scanf("%lld",&n);
	adj=vector<vector<PII> >(n);
	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)); }
	
	vector<pair<PII,int> > stack;
	vector<pair<ll,ll> > ans;
	stack.PB(MP(MP(0,-1),-1)); ans.PB(MP(1LL,0LL));
	while(!stack.empty()) {
		int at=stack.back().first.first,prev=stack.back().first.second; int &i=stack.back().second;
//		REP(j,max(SZ(stack),SZ(ans))) printf("%d %d %d / %lld %lld\n",j<SZ(stack)?stack[j].first.first:-2,j<SZ(stack)?stack[j].first.second:-2,j<SZ(stack)?stack[j].second:-2,j<SZ(ans)?ans[j].first:-2,j<SZ(ans)?ans[j].second:-2); puts("");
		if(i!=-1) {
			int to=adj[at][i].first,len=adj[at][i].second;
			pair<ll,ll> cur=ans.back(); ans.pop_back();
			ans.back().first+=cur.first;
			ans.back().second+=cur.second;
			ans.back().second+=cur.first*(n-cur.first)*len;
		}
		++i;
		if(i<SZ(adj[at])) {
			int to=adj[at][i].first,len=adj[at][i].second;
			if(to==prev) ++i,to=adj[at][i].first,len=adj[at][i].second;
			if(i<SZ(adj[at])) {
				stack.PB(MP(MP(to,at),-1)); ans.PB(MP(1LL,0LL));
			} else {
				stack.pop_back();
			}
		} else {
			stack.pop_back();
		}
	}
	
	ll res=ans.back().second;
	printf("%.3lf\n",1.0*res/(n*(n-1)/2));
}

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