#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <complex>
#include <iostream>
#include <algorithm>
#include <ctime>
#include <deque>
#include <bitset>
#include <cctype>
#include <utility>
#include <cassert>
using namespace std;
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
const int MN = 10111;
vector< pair<int,int > > ke[MN];
int sz[MN], father[MN];
void dfs(int u, int fu = -1) {
father[u] = fu;
sz[u] = 1;
REP(i,ke[u].size()) {
int v = ke[u][i].first;
if (v == fu) continue;
dfs(v, u);
sz[u] += sz[v];
}
}
int main() {
ios :: sync_with_stdio(false); cin.tie(NULL);
cout << (fixed) << setprecision(6);
int test; cin >> test;
while (test--) {
int n;
cin >> n;
FOR(i,1,n) ke[i].clear();
FOR(i,2,n) {
int u, v, c; cin >> u >> v >> c;
++u; ++v;
ke[u].push_back(make_pair(v, c));
ke[v].push_back(make_pair(u, c));
}
dfs(1);
long long sum = 0;
FOR(u,1,n)
REP(i,ke[u].size()) {
int v = ke[u][i].first;
if (u == father[v]) {
sum += ke[u][i].second * (long long) sz[v] * (n - sz[v]);
}
}
cout << (fixed) << setprecision(9) << sum / (n * (long long) (n-1) / (double) 2) << endl;
}
return 0;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHF1ZXVlPg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8IGVuZGw7IH0KCmNvbnN0IGludCBNTiA9IDEwMTExOwoKdmVjdG9yPCBwYWlyPGludCxpbnQgPiA+IGtlW01OXTsKaW50IHN6W01OXSwgZmF0aGVyW01OXTsKCnZvaWQgZGZzKGludCB1LCBpbnQgZnUgPSAtMSkgewogICAgZmF0aGVyW3VdID0gZnU7CiAgICBzelt1XSA9IDE7CiAgICBSRVAoaSxrZVt1XS5zaXplKCkpIHsKICAgICAgICBpbnQgdiA9IGtlW3VdW2ldLmZpcnN0OwogICAgICAgIGlmICh2ID09IGZ1KSBjb250aW51ZTsKCiAgICAgICAgZGZzKHYsIHUpOwogICAgICAgIHN6W3VdICs9IHN6W3ZdOwogICAgfQp9CgppbnQgbWFpbigpIHsKICAgIGlvcyA6OiBzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOyBjaW4udGllKE5VTEwpOwogICAgY291dCA8PCAoZml4ZWQpIDw8IHNldHByZWNpc2lvbig2KTsKICAgIGludCB0ZXN0OyBjaW4gPj4gdGVzdDsKICAgIHdoaWxlICh0ZXN0LS0pIHsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICBGT1IoaSwxLG4pIGtlW2ldLmNsZWFyKCk7CiAgICAgICAgRk9SKGksMixuKSB7CiAgICAgICAgICAgIGludCB1LCB2LCBjOyBjaW4gPj4gdSA+PiB2ID4+IGM7CiAgICAgICAgICAgICsrdTsgKyt2OwogICAgICAgICAgICBrZVt1XS5wdXNoX2JhY2sobWFrZV9wYWlyKHYsIGMpKTsKICAgICAgICAgICAga2Vbdl0ucHVzaF9iYWNrKG1ha2VfcGFpcih1LCBjKSk7CiAgICAgICAgfQogICAgICAgIGRmcygxKTsKCiAgICAgICAgbG9uZyBsb25nIHN1bSA9IDA7CiAgICAgICAgRk9SKHUsMSxuKQogICAgICAgICAgICBSRVAoaSxrZVt1XS5zaXplKCkpIHsKICAgICAgICAgICAgICAgIGludCB2ID0ga2VbdV1baV0uZmlyc3Q7CiAgICAgICAgICAgICAgICBpZiAodSA9PSBmYXRoZXJbdl0pIHsKICAgICAgICAgICAgICAgICAgICBzdW0gKz0ga2VbdV1baV0uc2Vjb25kICogKGxvbmcgbG9uZykgc3pbdl0gKiAobiAtIHN6W3ZdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIGNvdXQgPDwgKGZpeGVkKSA8PCBzZXRwcmVjaXNpb24oOSkgPDwgc3VtIC8gKG4gKiAobG9uZyBsb25nKSAobi0xKSAvIChkb3VibGUpIDIpIDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQoK