var a,b,c,w,l:array[0..1000]of longint;n,tt,t,i:longint;max:double;
procedure qs(l,r:longint);
var i,j,t,x:longint;
begin
i:=l;j:=r;x:=a[(l+r)div 2];
repeat
while a[i]<x do inc(i);while a[j]>x do dec(j);
if i<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
t:=c[i];c[i]:=c[j];c[j]:=t;
inc(i);dec(j);
end;
until i>j;
if i<r then qs(i,r);if l<j then qs(l,j);
end;
begin
assign(input,'treec.in');assign(output,'treec.out');
reset(input);rewrite(output);
read(t);
for tt:=1 to t do
begin
readln(n); max:=0;
for i:=1 to n do begin w[i]:=0;l[i]:=0;end;
for i:=1 to n-1 do readln(a[i],b[i],c[i]); qs(1,n-1);
for I:=1 to n-1 do
begin
w[b[i]]:=w[a[i]]+c[i];l[b[i]]:=l[a[i]]+1;
if w[b[i]]/l[b[i]]>max then max:=w[b[i]]/l[b[i]];
end;
writeln(max:0:2);
end;
close(output);
end.