#include <bits/stdc++.h>
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
 
using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> 
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
 
 
 
VI dice(const VI& cr, int z){
	auto nc = cr;
	if(z==0){  
		nc[0] = 7 - cr[1]; nc[1] = cr[0];
	}else if(z==1){
		nc[0] = 7 - cr[2];  nc[2] = cr[0];
	}else if(z==2){ 
		nc[0] = cr[1]; nc[1] = 7 - cr[0];
	}else if(z==3){ 
		nc[0] = cr[2]; nc[2] = 7 - cr[0];
	}else if(z==4){  
		nc[1] = 7 - cr[2]; nc[2] = cr[1];
	}else { 
		nc[1] = cr[2]; nc[2] = 7 - cr[1];
	}
	return nc;
}
 
 
int main(){
	int n;
	cin >>n;
	vector<VI> ds(n, VI(6));
	rep(i,n) rep(j,6) cin >> ds[i][j];
	
	vector<int> cr = {1,3,2};
	set<VI> st;
	rep(g, 7){
		rep(i,4){
			cr = dice(cr, 7);
			st.insert(cr);
		}
		cr = dice(cr, g<3? 1: 2);
	}
	vector<set<VI>> nst(n);
	rep(i,n) for(auto x: st){
		VI w1 = {ds[i][x[0]-1], ds[i][x[1]-1],ds[i][x[2]-1]};
		nst[i].insert(w1);
	}
	bool same=false;
	rep(i,n) rep2(j,i+1,n){
		if( nst[i] == nst[j] ){ same=true; break;}
	}
	cout <<(same? "No": "Yes") <<"\n";
	return 0;
}
