var was:array[1..100,1..1000] of longint;
    color:array[1..6] of longint;
    n,i,j,k,l:longint; 
begin
 assign(input,'c.in');   reset(input);
 assign(output,'c.out'); rewrite(output);
 read(n);
 k:=3;
  for i:=1 to 4 do
   begin
    was[1,i]:=k; was[2,i]:=k;
    inc(k);
end;
 k:=1;
 for i:=1 to 4 do
 begin
  was[5,i]:=k; was[6,i]:=k;
  inc(k);
end;
was[3,1]:=1; was[3,2]:=2; was[3,3]:=5; was[3,4]:=6; 
 for i:=1 to 4 do was[4,i]:=was[3,i];
 for i:=1 to n do
 begin
 read(color[1],color[2],color[3],color[4],color[5],color[6]);
 l:=0;
 for j:=1 to 6 do
 begin
 for k:=1 to 4 do
 if (color[j]=color[was[j,k]]) then begin l:=1; break; end;
if (l=1) then break;
end;
if (l=0) then writeln('NO') else writeln('YES');
end;
close(output);
end.
  