#include<iostream>

using namespace std;

struct kub
{
  int a[6];
};

bool check(kub a)
{
 for(int i=0;i<6;i++)
 {
  for(int j=i;j<6;j++)
  {
   if(i==j) continue;
   if(i==0 && j==1) continue;
   if(i==2 && j==3) continue;
   if(i==4 && j==5) continue;
   if(a.a[i]==a.a[j]) {return true;}
  }
 }
 return false;
}
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
int n; cin>>n;
for(int i=0;i<n;i++)
{
 kub temp;
 for(int j=0;j<6;j++)
  cin>>temp.a[j];
 if(check(temp))  cout<<"YES\n"; else cout<<"NO\n";
}
return 0;
}
