var t,w,i,j,tt:longint; n,z:longint; ans,cost:int64; max1,max2,c:array[0..101]of longint; s1,s:string; a:array[0..101]of string; x:boolean; function ok(s1,s2:string):boolean; begin if (length(s1)=length(s2))and(s1=s2) then begin ok:=true; exit; end; ok:=false; end; procedure v1(var x:int64;s:string); var i:longint; begin cost:=0; for i:=1 to length(s) do cost:=(ord(s[i])-48)+cost*10; end; begin read(t); for w:=1 to t do begin readln(n); ans:=0; z:=0; fillchar(max1,sizeof(max1),0); fillchar(max2,sizeof(max2),0); for i:=1 to n do begin readln(s); s1:=copy(s,1,pos(' ',s)-1); delete(s,1,pos(' ',s)); v1(cost,s); x:=true; for j:=1 to z do if (ok(s1,a[j])) then begin if (max2[j]