#include <cstdio>
#include <iostream>
#define MAXN 11
#define MAXM 7
using namespace std;

int n;
long f[MAXN][MAXM];

int main(){
	freopen("C.in","r",stdin); freopen("C.out","w",stdout);
	scanf("%d",&n);
	int c;
	bool ok;
	for (int i = 0; i < n; i++){
		memset(f,0,sizeof(f));
		for (int j = 1; j <= 6; j++){
			scanf("%d",&c);
			f[c][j] = 1;
		}
		//check
		for (int k = 1; k <= 10; k++){
			ok = false;
			ok = ok || (f[k][1] && f[k][5]);
			ok = ok || (f[k][1] && f[k][3]);
			ok = ok || (f[k][1] && f[k][6]);
			ok = ok || (f[k][1] && f[k][4]);

			ok = ok || (f[k][2] && f[k][5]);
			ok = ok || (f[k][2] && f[k][3]);
			ok = ok || (f[k][2] && f[k][6]);
			ok = ok || (f[k][2] && f[k][4]);

			ok = ok || (f[k][3] && f[k][5]);
			ok = ok || (f[k][3] && f[k][6]);

			ok = ok || (f[k][4] && f[k][5]);
			ok = ok || (f[k][4] && f[k][6]);

			if (ok) break;
		}
		if (ok) printf("YES\n");
		else printf("NO\n");
	}
	fclose(stdin); fclose(stdout);
	return 0;       
}