#include <bits/stdc++.h>
using namespace std;

bool isSame(vector<int> a, vector<int> b) {
	for (int i = 0; i < 6; ++i) {
		if (a[i] != b[i]) return false;
	}
	return true;
}

bool areSame(vector<int> s, vector<int> b) {
	string com = "NNNNEEEE";
	int tmp;
	for (int n = 0; n < 8; ++n) {
		do {
			for (int i = 0; i < n; ++i) {
				if(isSame(s, b)) {
					return true;
				}
				if (com[i] == 'N') {
					tmp = s[5];
					s[5] = s[4];
					s[4] = s[0];
					s[0] = s[1];
					s[1] = tmp;
				}
				else if (com[i] == 'E') {
					tmp = s[5];
					s[5] = s[2];
					s[2] = s[0];
					s[0] = s[3];
					s[3] = tmp;
				}
			}
		} while (next_permutation(com.begin(), com.end()));
	}
	return false;
}

signed main() {
	vector<int> s(6), b(6);
	int n;
	cin >> n;

	for (int i = 0; i < 6; ++i) {
		cin >> s[i];
	}

	for (int loop = 1; loop < n; ++loop) {
		for (int i = 0; i < 6; ++i) {
			cin >> b[i];
		}
		if (areSame(s, b)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

