#include <iostream>
#include <vector>
#include <string>

using namespace std;

enum class Direction {
	North = 0,
	East,
	South,
	West,

	up = North,
	right,
	down,
	left,
};

struct NeighborData {
	int index;
	Direction direction;
};

class Dice
{
private:
	int number[6];
	struct state {
		int topSurfaceIndex;
		Direction direction;
	} currentState;
	string rollOrder;
	// NeighborData neighbor[6][4]
	const NeighborData neighborTable[6][4] = {
	    /* up,                   right,                 down,                  left     */
	    {{4, Direction::South}, {2, Direction::West}, {1, Direction::North}, {3, Direction::East}},
	    {{0, Direction::North}, {2, Direction::North}, {5, Direction::North}, {3, Direction::North}},
	    {{0, Direction::East}, {4, Direction::North}, {5, Direction::West}, {1, Direction::North}},
	    {{0, Direction::West}, {1, Direction::North}, {5, Direction::East}, {4, Direction::North}},
	    {{0, Direction::South}, {3, Direction::North}, {5, Direction::South}, {2, Direction::North}},
	    {{1, Direction::North}, {2, Direction::East}, {4, Direction::South}, {3, Direction::West}}};

public:
	Dice()
	: currentState({0, Direction::North}) {}

	void input() {
		inputNumber();
		inputRollOrder();
	}

	void inputNumber() {
		for(auto&& e : number) {
			cin >> e;
		}
	}

	void inputRollOrder() {
		cin >> rollOrder;
	}

	void executeRollOrder() {
		while(1) {
			char dir = fetchRollOrder();
			if(0 == dir) { return; }
			roll(dir);
		}
	}

	char fetchRollOrder() {
		char c;
		if(0 < rollOrder.length()) {
			c = rollOrder.front();
			rollOrder.erase(rollOrder.begin());
		} else {
			c = 0;
		}
		return c;
	}

	void roll(char rollDirection) {
		int backupTopSurfaceIndex = currentState.topSurfaceIndex;
		Direction dir;
		switch(currentState.direction) {
			case Direction::North:
				switch(rollDirection) {
					case 'N': dir = Direction::down; break;
					case 'E': dir = Direction::left; break;
					case 'W': dir = Direction::right; break;
					case 'S': dir = Direction::up; break;
					default: return;
				}
				break;

			case Direction::East:
				switch(rollDirection) {
					case 'N': dir = Direction::right; break;
					case 'E': dir = Direction::down; break;
					case 'W': dir = Direction::up; break;
					case 'S': dir = Direction::left; break;
					default: return;
				}
				break;

			case Direction::South:
				switch(rollDirection) {
					case 'N': dir = Direction::up; break;
					case 'E': dir = Direction::right; break;
					case 'W': dir = Direction::left; break;
					case 'S': dir = Direction::down; break;
					default: return;
				}
				break;

			case Direction::West:
				switch(rollDirection) {
					case 'N': dir = Direction::left; break;
					case 'E': dir = Direction::up; break;
					case 'W': dir = Direction::down; break;
					case 'S': dir = Direction::right; break;
					default: return;
				}
				break;
			default: return;
		}

		currentState.topSurfaceIndex = neighborTable[backupTopSurfaceIndex][(int)dir].index;
		currentState.direction = (Direction)(((int)neighborTable[backupTopSurfaceIndex][(int)dir].direction + (int)currentState.direction) % 4);
	}

	int getTopSurfaceNumber() const {
		return number[currentState.topSurfaceIndex];
	}

	int getBottomSurfaceNumber() const {
		return number[5 - currentState.topSurfaceIndex];
	}

	int getRightSurfaceNumber() const {
		Direction dir;
		switch(currentState.direction) {
			case Direction::North: dir = Direction::right; break;
			case Direction::East: dir = Direction::up; break;
			case Direction::South: dir = Direction::left; break;
			case Direction::West: dir = Direction::down; break;
			default: break;
		}
		return number[neighborTable[currentState.topSurfaceIndex][(int)dir].index];
	}

	int getLeftSurfaceNumber() const {
		Direction dir;
		switch(currentState.direction) {
			case Direction::North: dir = Direction::left; break;
			case Direction::East: dir = Direction::down; break;
			case Direction::South: dir = Direction::right; break;
			case Direction::West: dir = Direction::up; break;
			default: break;
		}
		return number[neighborTable[currentState.topSurfaceIndex][(int)dir].index];
	}

	int getFrontSurfaceNumber() const {
		Direction dir;
		switch(currentState.direction) {
			case Direction::North: dir = Direction::down; break;
			case Direction::East: dir = Direction::right; break;
			case Direction::South: dir = Direction::up; break;
			case Direction::West: dir = Direction::left; break;
			default: break;
		}
		return number[neighborTable[currentState.topSurfaceIndex][(int)dir].index];
	}

	int getBackSurfaceNumber() const {
		Direction dir;
		switch(currentState.direction) {
			case Direction::North: dir = Direction::up; break;
			case Direction::East: dir = Direction::left; break;
			case Direction::South: dir = Direction::down; break;
			case Direction::West: dir = Direction::right; break;
			default: break;
		}
		return number[neighborTable[currentState.topSurfaceIndex][(int)dir].index];
	}

	void setCurrentState(const state st) {
		currentState = st;
	}

	state identifyCurrentState(const int topNumber, const int frontNumber) const {
		int topIndex, frontIndex;
		topIndex = convertNumber2Index(topNumber);
		frontIndex = convertNumber2Index(frontNumber);

		try {
			for(int i = 0; i < 4; ++i) {
				if(frontIndex == neighborTable[topIndex][i].index) {
					switch((Direction)i) {
						case Direction::up: return {topIndex, Direction::South};
						case Direction::right: return {topIndex, Direction::East};
						case Direction::down: return {topIndex, Direction::North};
						case Direction::left: return {topIndex, Direction::West};
						default: break;
					}
				}
			}
			throw "Index Error\n";
		} catch(char* arg) {
			cout << arg;
			return {0, Direction::North};
		}
	}

	int convertNumber2Index(const int _number) const {
		try {
			for(int i = 0; i < 6; ++i) {
				if(_number == number[i]) {
					return i;
				}
			}
			throw "Index Error\n";
		} catch(char* arg) {
			cout << arg;
			return 0;
		}
	}

	bool isSame(const Dice _dice) {
		for(int i = 0; i < 6; ++i) {
			if(_dice.number[currentState.topSurfaceIndex] == this->number[i]) {
				// 上面を合わせる
				this->setCurrentState({i, this->currentState.direction});

				// 下面が一致するか確認
				if(_dice.getBottomSurfaceNumber() != this->getBottomSurfaceNumber()) { continue; }

				// 右面を合わせる => 向きを一致させる
				for(int j = 0; j < 4; ++j) {
					// 未確認の奥、手前、左面、右面の確認
					if((_dice.getBackSurfaceNumber() == this->getBackSurfaceNumber()) && (_dice.getFrontSurfaceNumber() == this->getFrontSurfaceNumber()) && (_dice.getLeftSurfaceNumber() == this->getLeftSurfaceNumber()) && (_dice.getRightSurfaceNumber() == this->getRightSurfaceNumber())) {
						return true;
					}

					if(3 > j) {
						// 鉛直方向を軸とした90°回転
						this->setCurrentState({this->currentState.topSurfaceIndex, (Direction)(((int)(this->currentState.direction) + 1) % 4)});
					}
				}
			}
		}
		return false;
	}
};

int main() {
	bool isAllDefarenceDices = true;
	int n;
	cin >> n;

	vector<Dice> dices(n);
	for(auto&& e : dices){
		e.inputNumber();
	}

	for(int i = 0; i < n - 1; ++i){
		for(int j = i + 1; j < n; ++j){
			if(dices[i].isSame(dices[j])) {
				isAllDefarenceDices = false;
				break;
			}
		}
	}

	cout << (isAllDefarenceDices ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3160