#include <iostream>
using namespace std;

static const int ds = 6;

void dsort( int a[], int i0, int i1, int i2, int i3 ) {
	int ta[] = { a[i0], a[i1], a[i2], a[i3] };
	int min = ta[0];
	for( int i = 0; i < 4; i++ ) {
		if( min > ta[i] ) {
			min = ta[i];
		}
	}

	int t = 0;
	while( true ) {
		if( a[i0] == min ) {
			break;
		}
		t = a[i0];a[i0]=a[i1];a[i1]=a[i2];a[i2]=a[i3];a[i3]=t;
	}

	return;
}

bool dcomp( int a[], int b[] )
{
	for( int i = 0; i < ds; i++ ) {
		if( a[i] != b[i] ) {
			return false;
		}
	}

	return true;
}

bool dcheck( int a[], int b[100][ds], int last ) {
	bool ret = false;
	for( int i = 0; i < last; i++ ) {
		ret = dcomp( a, b[i] );
		if( ret == true ) {
			break;
		}
	}
	return ret;
}

int main()
{
	int n, dx[ds], dbuff[100][ds];
	bool ret = false;

	cin >> n;

	for( int i = 0; i < n; i++ ) {
		for( int j = 0; j < ds; j++ ) {
			cin >> dx[j];
		}
		dsort( dx, 0, 1, 5, 4 );
		dsort( dx, 0, 3, 5, 2 );
		dsort( dx, 1, 2, 4, 3 );

		ret = dcheck( dx, dbuff, i );
		if( ret == true ) {
			break;
		}

		for( int j = 0; j < ds; j++ ) {
			dbuff[i][j] = dx[j];
		}
	}

	cout << (ret?"No":"Yes") << endl;

	return 0;
}
