#include <stdio.h>
#include <iostream>

using namespace std;

int a[1000][1000];

bool mogno(int front,int back,int left,int right,int up,int down){

	if((front==left)||(front==right)||(front==up)||(front==down)){
	return true;
		}
	if((back==left)||(back==right)||(back==up)||(back==down)){
	return true;
		}

	if((left==front)||(left==back)||(left==up)||(left==down)){
	return true;
		}
	if((right==front)||(right==back)||(right==up)||(right==down)){
	return true;
		}

	if((up==front)||(up==back)||(up==left)||(up==right)){
	return true;
		}
	if((down==front)||(down==back)||(down==left)||(down==right)){
	return true;
		}
//esli ne odno iz etih to false
return false;
}

int main(){

freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);
	
int N;
cin>>N;
for(int i=0;i<N;i++)
for(int j=0;j<6;j++){
cin>>a[i][j];
}

for(int i=0;i<N;i++){
    if(mogno(a[i][0],a[i][1],a[i][2],a[i][3],a[i][4],a[i][5])) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
	
	return 0;
}