var t,w,a,b,c,i,tot,j,k,x,y:longint; f:boolean; ch,ch1:char; pa,pb,pc:array['A'..'Z'] of longint; begin readln(t); for w:=1 to t do begin readln(a,b,c); x:=0;y:=0; fillchar(pa,sizeof(pa),0); fillchar(pb,sizeof(pb),0); fillchar(pc,sizeof(pc),0); for i:=1 to a do begin readln(ch,ch1,tot);pa[ch]:=tot;end; for i:=1 to b do begin readln(ch,ch1,tot);pb[ch]:=tot;end; for i:=1 to c do begin readln(ch,ch1,tot);pc[ch]:=tot;end; for j:=1 to 100 do begin if (x>0)and(y>0) then break; for k:=1 to 100 do begin f:=true; for ch:='A' to 'Z' do begin if (pc[ch]=0)and(pa[ch]=0)and(pb[ch]=0) then continue; if pa[ch]*j+pb[ch]*k<>pc[ch] then begin f:=false;break;end; end; if f then begin x:=j;y:=k;break;end; end; end; if (x>0)and(y>0) then writeln(x,' ',y) else writeln('NO'); end; end.