/*
  [BAPC'07] AVERAGE DISTANCE
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <iomanip>
#include <vector>

int N;
double res;
vector<vector<int> > ch;
vector<vector<int> > len;

int go (int n, int par, double edgelen) {
  int cnt=1;
  for (int i=0; i<ch[n].size(); i++)
    if (ch[n][i]!=par) cnt += go(ch[n][i],n,len[n][i]);
  res += cnt * (N-cnt) * edgelen;
  return cnt;
}

int main () {

  int runs;
  cin>>runs;
  while (runs--) {
    cin>>N;
    ch=len=vector<vector<int> >(N);
    for (int i=0; i<N-1; i++) {
      int a,b,l;
      cin>>a>>b>>l;
      ch[a].push_back(b);
      ch[b].push_back(a);
      len[a].push_back(l);
      len[b].push_back(l);
    }
      
    res=0;
    go(0,-1,0);
    cout << setprecision(10) << res/(0.5*N*(N-1)) << endl;
  }
  
  return 0;
}
