#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=10010;
struct node
{
int v,w;
}a,b;
vector<node>tree[maxn];
int sum[maxn],n;
ll dp[maxn];
void dfs(int cur,int fa)
{
sum[cur]=1;
for(int i=0;i<tree[cur].size();i++)
{
int son=tree[cur][i].v;
ll len=tree[cur][i].w;
if(son==fa) continue;
dfs(son,cur);
sum[cur]+=sum[son];
dp[cur]+=dp[son]+(n-sum[son])*sum[son]*len;
}
}
int main()
{
int t,x,y,z;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
tree[i].clear();
memset(sum,0,sizeof(sum));
memset(dp,0,sizeof(dp));
for(int i=1;i<n;i++)
{
scanf("%d%d%d",&x,&y,&z);
a.v=x;
a.w=b.w=z;
b.v=y;
tree[x].push_back(b);
tree[y].push_back(a);
}
dfs(0,-1);
printf("%f\n",dp[0]*2.0/n/(n-1));
}
return 0;
}