{$ifdef fpc} {$mode delphi} {$endif}
{$apptype console}
{$s+,i+,r+,q+,v+,d+,l+,o-}
const
	filein = 'C.in';
	fileout = 'C.out';
	n = 6;
var
	a: array[1..n]of longint;
	t,i: longint; flag: boolean;

begin
	assign(input,filein);reset(input);assign(output,fileout);rewrite(output);
	read(t); while t > 0 do begin
		for i := 1 to n do read(a[i]); dec(t);
		flag := (a[1] = a[5]) or (a[4] = a[5]) or (a[2] = a[5]) or (a[3] = a[5])
		     or (a[1] = a[6]) or (a[4] = a[6]) or (a[2] = a[6]) or (a[3] = a[6])
		     or (a[1] = a[3]) or (a[1] = a[4]) or (a[2] = a[3]) or (a[2] = a[4]);
	       	if flag then writeln('YES') else writeln('NO');
	end;
	close(output);
end.