program C;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
 neg: array[1..6] of integer = (2,1,4,3,6,5);
 ans: array[0..1] of string = ('NO','YES');  
var
 n,m: integer;
 cubcount: integer;
 data: array of array[1..6] of integer;
 answer: array of boolean; 

procedure LoadData;
var
 f: textfile;
 i,t: integer;
begin
 AssignFile(f,'C.in');
 Reset(f);
 ReadLn(f,cubcount);
 setLength(data,cubcount+1);
 setLength(answer,cubcount+1);

 for i:=1 to cubcount do begin
  for t:=1 to 6 do read(f,data[i,t]);
  readln(f);
 end;
 
 CloseFile(f);
end;

procedure Mozg;
var
 i,t,z: integer;
 temp: integer;
begin
 for i:=1 to cubcount do begin
  answer[i]:=false;
  for t:=1 to 6 do begin
   for z:=1 to 6 do
    if (z<>t) and (neg[t]<>z) then
     if data[i][t]=data[i][z] then begin
      answer[i]:=true;
      break;
     end;
   if answer[i] then break;
  end;
 end;
end;

procedure WriteData;
var
 f: textfile;
 i: integer;
begin
 AssignFile(f,'C.out');
 ReWrite(f);
 for i:=1 to cubcount do WriteLn(f,ans[ord(answer[i])]);
 CloseFile(f);
end;

begin
 LoadData;
 Mozg;
 WriteData;
end.
