type nodd=record
n,y,d:longint;
end;
var a:array[0..1100]of longint;
b:array[0..1100]of nodd;
n,t,i,x,tt,k:longint;
max:double;
procedure init;
begin
readln(n);
fillchar(a,sizeof(a),0);
for i:=1 to n-1 do
begin
read(x,b[i].y,b[i].d);
b[i].n:=a[x]; a[x]:=i;
end;
end;
procedure dfs(t,s:longint;d:int64);
var p:longint;
begin
if t>0 then if d/s>max then max:=d/s;
p:=a[t];
while p<>0 do
begin
dfs(b[p].y,s+1,d+b[p].d);
p:=b[p].n;
end;
end;
procedure work;
begin
if n=1 then max:=0 else max:=-100000000000;
dfs(0,0,0);
writeln(max:0:2);
end;
begin
assign(input,'treec.in');reset(input);
assign(output,'treec.out');rewrite(output);
readln(tt);
for k:=1 to tt do
begin
init;
work;
end;
close(input);close(output);
end.