{$A+,B-,D+,E+,F+,G-,I+,L+,N+,O-,P-,Q+,R+,S+,T+,V+,X+,Y+}
{$DEFINE init_ECHO}
{$M 65520,0,655360}
VAR
n:byte;
a,b,c,d,e,f,i: integer;
flag: byte;
ot: array[0..1] of string;
BEGIN
assign(input,'C.in');
reset(input);
assign(output,'C.out');
rewrite(output);

ot[0]:='NO';
ot[1]:='YES';
read(input,n); readln(input);
 for i:=1 to n do begin
  read(input,a); read(input);
  read(input,b); read(input);
  read(input,c); read(input);
  read(input,d); read(input);
  read(input,e); read(input);
  read(input,f); read(input);
  flag:=0;
  if a = f then flag:=1;
  if a = c then flag:=1;
  if a = d then flag:=1;
  if a = e then flag:=1;

  if b = f then flag:=1;
  if a = c then flag:=1;
  if a = d then flag:=1;
  if a = e then flag:=1;

  if c = f then flag:=1;
  if c = e then flag:=1;

  if d = f then flag:=1;
  if d = e then flag:=1;

  writeln(output,ot[flag]);
 end;
close(input);
close(output);
END.
