var
	a : array[ 1..6 ] of byte;
	j , N , i : byte;
	ok : boolean;

begin
 assign( input , 'C.in' );
  reset( input );
 assign( output , 'C.out' );
  rewrite( output );
 readln( N );
 for i := 1 to N do
  begin
   ok := false;
   for j := 1 to 6 do
    read( a[ j ] );
   j := 3;
   while j <> 1 do
    begin
     if a[ j ] = a[ 1 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   j := 3;
   while j <> 1 do
    begin
     if a[ j ] = a[ 2 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   j := 5;
   while j <> 3 do
    begin
     if a[ j ] = a[ 3 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   j := 5;
   while j <> 3 do
    begin
     if a[ j ] = a[ 4 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   j := 1;
   while j <> 5 do
    begin
     if a[ j ] = a[ 5 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   j := 1;
   while j <> 5 do
    begin
     if a[ j ] = a[ 6 ] then
      ok := true;
     inc( j );
     if j = 7 then
      j := 1;
    end;
   if ok then
    writeln( 'YES' )
   else
    writeln( 'NO' );
  end;
end.