var
  a     : array [1..6] of integer;
  i,n,p,z,l,pr,up,d:integer;

function check(var p,z,l,pr,up,d:integer):boolean;
begin
   check:=false;
   if (p=l)then check:=true else
   if (p=pr)then check:=true else
   if (p=up)then check:=true else
   if (p=d) then check:=true else
   if (pr=up)then check:=true else
   if (pr=z)then check:=true else
   if (pr=d) then check:=true else
   if (z=up)then check:=true else
   if (z=d)then check:=true else
   if (z=l) then check:=true else
   if (l=up)then check:=true else
   if (l=d) then check:=true;
end;

begin
  assign(input,'c.in');
  assign(output,'c.out');
  reset(input);rewrite(output);
    read(n);
    for i:=1 to n do begin
      read(p,z,l,pr,up,d);
      if check(p,z,l,pr,up,d)=true then writeln('YES') else writeln('NO');
    end;
  close(input);close(output);
end.
