#include <iostream>

using namespace std;

class dice{
	private:
		int top;
		int front;
		int right;
		int left;
		int back;
		int bottom;
	public:
		dice();
		dice(int top,int front,int right,int left,int back,int bottom);
		void roll(char ch);
		void changstatus(int new_top,int new_front,int new_right,int new_left,int new_back,int new_bottom);
		int gettop();
		int getfront();
		int getright();
		int getleft();
		int getback();
		int getbottom();
		int compare(dice another_dice);
		void getallsides();
};

dice::dice(){
	this->top = 1;
	this->front = 2;
	this->right = 3;
	this->left = 4;
	this->back = 5;
	this->bottom = 6;

}

dice::dice(int top,int front,int right,int left,int back,int bottom){
	this->top=top;
	this->front=front;
	this->right=right;
	this->left=left;
	this->back=back;
	this->bottom=bottom;
}

void dice::roll(char ch){
	int temp;
	switch (ch){
		case 'E':
			temp = this->top;
			this->top = left;
			this->left = bottom;
			this->bottom = right;
			this->right = temp;
			break;
		case 'W':
			temp = this->top;
			this->top = right;
			this->right = bottom;
			this->bottom = left;
			this->left = temp;
			break;
		case 'S':
			temp = this->top;
			this->top = back;
			this->back = bottom;
			this->bottom = front;
			this->front = temp;
			break;
		case 'N':
			temp = this->top;
			this->top = front;
			this->front = bottom;
			this->bottom = back;
			this->back = temp;
			break;
	}
}

void dice::getallsides(){
	cout << top << " "<<front<<" "<<right<<" "<<left<<" "<<back<<" "<<bottom<<endl;
}

int dice::gettop(){
	return this->top;
}

int dice::getbottom(){
	return this->bottom;
}

int dice::getfront(){
	return this->front;
}

int dice::getback(){
	return this->back;
}

int dice::getleft(){
	return this->left;
}

int dice::getright(){
	return this->right;
}

int dice::compare(dice another_dice){
	string method[]={"","N","N","N","EN","WN"};
	string temp;
    bool flag;
    dice temp_dice=another_dice;
    
	flag = false;
	for(int i=0;i<6;i++){
		temp=method[i];
		if(i==4||i==5){
			temp_dice = another_dice;
		}		
		for(int j=0;j<temp.length();j++){
			temp_dice.roll(temp[j]);
		}

		for(int j=0;j<4;j++){
			temp_dice.roll('E');
			//temp_dice.getallsides();
			if(this->gettop()==temp_dice.gettop()&&
			   this->getfront()==temp_dice.getfront()&&
			   this->getright()==temp_dice.getright()&&
			   this->getleft()==temp_dice.getleft()&&
			   this->getback()==temp_dice.getback()&&
			   this->getbottom()==temp_dice.getbottom()){
				flag = true;
				break;
			}
		}

		if (flag==true){
			return 1;
		}
	}

	return -1;
	
}


void dice::changstatus(int new_top,int new_front,int new_right,int new_left,int new_back,int new_bottom){
	this->top = new_top;
	this->front = new_front;
	this->right = new_right;
	this->left = new_left;
	this->back = new_back;
	this->bottom = new_bottom;	
}

int main(){

	int top,front,right,left,back,bottom;
	dice *pdice,*p,*q;
	int count;
	
	cin >> count;
	pdice = new dice[count];
	q = pdice;
	
	for(int i=0;i<count;i++){
		cin >>top>>front>>right>>left>>back>>bottom;
		q->changstatus(top,front,right,left,back,bottom);
		q++;		
	}
	
	bool flag = false;
	p=pdice;
	for(int i=0;i<count;i++){
		q = p+1;
		for(int j=1;j<count;j++){
			if(p->compare(*q)==1){
				flag=true;
				break;
			}
			q++;
		}
		p++;
	}
	
	if(flag){
		cout<<"No"<<endl;
	}	
	else{
		cout<<"Yes"<<endl;
	}


	delete [] pdice;
	return 0;
}



Measured memory_bytes: 3204