program c;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, ii, jj: byte;
  color: array [1..10, 1..6] of byte;

function ShowKub (ii, i, j: byte):boolean;
begin
 result:=false;
  if color [ii, i] = color [ii, j] then result:=true;
end;

begin
 assign (input, 'c.in'); reset (input);
 assign (output, 'c.out'); rewrite (output);
 readln (n);
  for ii:=1 to n do begin
   for jj:=1 to 6 do read (color [ii, jj]);

  if ShowKub (ii, 1, 3) or ShowKub (ii, 1, 4) or ShowKub (ii, 1,5) or ShowKub (ii, 1,6) or
  ShowKub (ii, 2,3) or ShowKub (ii, 2,4) or ShowKub (ii, 2,5) or ShowKub (ii, 2,6) or
  ShowKub (ii, 3,5) or ShowKub (ii, 3,6) or ShowKub (ii, 4,5) or ShowKub (ii, 4,6) then
   writeln ('YES') else writeln ('NO');
  end;
 close (output);
end.
