program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var fin,fout:textfile;
i,j,n,j1,j2:integer;
m:array[1..100,1..100] of integer;
otvet:array [1..10] of string;

begin
  assign(fin,'c.in');
  reset(fin);
  assign(fout,'c.out');
  rewrite(fout);
  read(fin,n);

  for i:=1 to n do
    begin
    for j:=1 to 6 do
    read(fin,m[i,j]);
    end;

  for i:=1 to n do
  otvet[i]:='NO';

  for i:=1 to n do

  for j1:=1 to 6 do
  for j2:=j1+1 to 6 do
    if (m[i,j1]=m[i,j2]) and (abs(j2-j1)<>1) then
    otvet[i]:='YES';

    for i:=1 to n do
      begin
      writeln(fout,otvet[i]);
      end;

      
    close(fout);
    close(fin);

end.
