//* Problem  : A Average distance
//* Contest  : BAPC - 2007
//* Type     : Solution
//* Date     : 2008.08.05
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

typedef pair <int,int> PIII;
typedef vector <int> VI;
typedef vector <vector<int> > VVI;
typedef vector <pair<int,int> > VPII;
typedef vector <vector<pair<int,int> > > VVPII;

#define int64 long long
#define PI (2.0 * acos(0.0))
#define MP make_pair
#define PB push_back
#define SZ(a) (int)a.size()
#define FOR(i, n) for (int i = 0; i < (int)n; i++)
#define FORSZ(i, a) FOR(i, SZ(a))
#define FORE(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(a); i >= int(b); i--)
#define INF 1000000000
#define INFL 1000000000000000000LL
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define CLEARA(a) memset(a, 0, sizeof(a))

inline int si(){int tt; scanf("%d", &tt); return tt;}

int64 res;

int n;

VVPII a;

VI b;

int dfs(int v)
{
	b[v] = 1;
	int r = 1;
	FORSZ(i, a[v])
	{
		int t = a[v][i].first;
		int w = a[v][i].second;
		if (!b[t])
		{
			int k = dfs(t);
			res += (int64)(n-k)*k*w;
			r += k;
		}
	}
	return r;
}

void solve()
{
	res = 0;
	dfs(0);
}

void result()
{
	printf("%.10lf\n", 2.0 * res / n / (n - 1));
}

int main()
{
#ifdef _DEBUG
	freopen("1064", "r", stdin);
#endif
	int nt = si();
	while (nt--)
	{
		n = si();
		a.assign(n, VPII());
		b.assign(n, 0);
		FOR(i, n - 1)
		{
			int v1 = si(), v2 = si(), w = si();
			a[v1].PB(MP(v2, w));
			a[v2].PB(MP(v1, w));
		}
		solve();
		result();
	}
	return 0;
}

