var a:array[1..100,1..1000] of longint;
    c: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
          a[1,i]:=k; a[2,i]:=k;
          inc(k);
        end;      k:=1;
      for i:=1 to 4 do
       begin
        a[5,i]:=k; a[6,i]:=k;
        inc(k);
       end;
      a[3,1]:=1; a[3,2]:=2; a[3,3]:=5; a[3,4]:=6; for i:=1 to 4 do a[4,i]:=a[3,i];
     for i:=1 to n do
      begin
       read(c[1],c[2],c[3],c[4],c[5],c[6]); l:=0;
        for j:=1 to 6 do
         begin
          for k:=1 to 4 do
           if (c[j]=c[a[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.