#include<iostream>
#include<string>

using namespace std;

enum Diceface {
	DICETOP,
	DICEFRONT,
	DICERIGHT,
	DICELEFT,
	DICEBACK,
	DICEBOTTOM,
	DICENUM
};

class Dice {
private:
	int *face;
public:
	Dice( ) { face = new int[6]; }
	Dice( int top, int front, int right, int left, int back, int bottom ) {
		face = new int[6];
		
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	}
	~Dice( ) {
		delete [ ] face;
	}
	void setFace( int top, int front, int right, int left, int back, int bottom ) {
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	
		return;
	}
	void roll( string cmd ) {
		int t;
		for( int i=0; i<cmd.length(); i++ ) {
			if( 'E' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICELEFT];
				face[DICELEFT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICERIGHT];
				face[DICERIGHT] = t;
			} else if( 'N' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICEFRONT];
				face[DICEFRONT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICEBACK];
				face[DICEBACK] = t;
			} else if( 'S' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICEBACK];
				face[DICEBACK] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICEFRONT];
				face[DICEFRONT] = t;
			} else if( 'W' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICERIGHT];
				face[DICERIGHT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICELEFT];
				face[DICELEFT] = t;
			} else if( 'M' == cmd[i] ) {
				t = face[DICEBACK];
				face[DICEBACK] = face[DICERIGHT];
				face[DICERIGHT] = face[DICEFRONT];
				face[DICEFRONT] = face[DICELEFT];
				face[DICELEFT] = t;
			}
		}
		return;
	}
	int getFace( int diceface ) {
		return face[ diceface ];
	}

	bool isDiff( Dice &dice ) {
		int t, f, r, l, ba, bo;
		int i, cnt;

		t = dice.getFace( DICETOP );
		f = dice.getFace( DICEFRONT );
		r = dice.getFace( DICERIGHT );
		l = dice.getFace( DICELEFT );
		ba = dice.getFace( DICEBACK );
		bo = dice.getFace( DICEBOTTOM );
		cnt = 0;
		while( cnt < DICENUM ) {
		    switch( cnt ) {
		        case DICETOP:
		                cnt++;
		            break;
		        case DICEFRONT:
		                dice.roll( "N" );
		                cnt++;
		            break;
		        case DICERIGHT:
		                dice.roll( "W" );
		                cnt++;
		            break;
		        case DICELEFT:
		                dice.roll( "E" );
		                cnt++;
		            break;
		        case DICEBACK:
		                dice.roll( "S" );
		                cnt++;
		            break;
		        case DICEBOTTOM:
		                dice.roll( "SS" );
		                cnt++;
		            break;
		        }
				if( dice.getFace( DICETOP ) == face[ DICETOP ] ) {
					for( i=0; i<3; i++ ) {
						if( dice.getFace( DICEFRONT ) == face[ DICEFRONT ] ) { break; }
						dice.roll( "M" );
					}
					for( i=0; i<6; i++ ) {
						if( dice.getFace( i ) != face[ i ] ) { break; }
					}
					if( DICENUM == i ) { break; }
				}
				dice.setFace( t, f, r, l, ba, bo );
		}
		
		dice.setFace( t, f, r, l, ba, bo );
	
		if( DICENUM == i ) {
			return false;
		} else {
			return true;
		}
	}

};

int main( )
{
	int t, f, r, l, ba, bo;
	int n;
	
	cin>>n;
	Dice *dice = new Dice[n];
	if( NULL == dice ) { return 0; }
	
	int cnt = 0;
	while( cnt < n ) {
		cin>>t>>f>>r>>l>>ba>>bo;
		dice[ cnt++ ].setFace( t, f, r, l, ba, bo );
	}
	
	bool isDiff = false;
	for( int i=0; i<n-1; i++ ) {
		for( int j=i+1; j<n; j++ ) {
			if( !( isDiff = dice[i].isDiff( dice[j] ) ) ) { break; }
		}
		if( !isDiff ) { break; }
	}
	if( isDiff ) {
		cout<<"Yes"<<endl;		
	} else {
		cout<<"No"<<endl;
	}

	delete [ ] dice; 
	
	return 0;
}

Measured memory_bytes: 1204