#include<iostream>
#include<string>
#include<vector>
using namespace std;

bool dice(vector<int>a,vector<int>b) {
	vector<int>m(6);
	for (int h = 0; h<6; h++)
		m[h] = a[h];
	for (int e = 0; e<4; e++) {
		a[0] = m[1]; a[1] = m[5]; a[4] = m[0]; a[5] = m[4];
		for (int h = 0; h<6; h++)
			m[h] = a[h];
		for (int f = 0; f<4; f++) {
			a[0] = m[3]; a[2] = m[0]; a[3] = m[5]; a[5] = m[2];
			for (int h = 0; h<6; h++)
				m[h] = a[h];
			for (int g = 0; g<4; g++) {
				a[2] = m[1]; a[4] = m[2]; a[1] = m[3]; a[3] = m[4];
				for (int h = 0; h<6; h++)
					m[h] = a[h];
				if (a == b)
				{
					return true;
				}
			}
		}
		if (e == 3) { return false; }
	}
}
int main() {
	int a;
	cin >> a;
	vector<vector<int>>s(0);
	for (int b = 0; b < a; b++) {
		vector<int>e(6);
		for (int c = 0; c<6; c++) {
			int d;
			cin >> d;
			e[c] = d;
		}
		s.push_back(e);
	}
	for (int f = 0; f < s.size(); f++) {
		for (int g = f + 1; g < s.size(); g++) {
			if (dice(s[f], s[g])) { cout << "No" << endl; goto l; }
		}
		if (s.size() - f == 1) { cout << "Yes" << endl; break; }
	}
l:;
}