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

using namespace std;

class Dice
{
public:
	Dice()
	{
	}
	Dice(unsigned int in[6])
	{
		for (int i = 0; i < 6; i++)
		{
			label[i] = in[i];
			//cout << "label[" << i << "]=" << label[i];
		}
		//cout << endl;
		Reset();
	}
	~Dice()
	{
	}
	void Reset()
	{
		N = 5;
		E = 3;
		S = 2;
		W = 4;
		F = 1;
		B = 6;
	}
	void Run(string &cmd)
	{
		for (int i = 0; i < cmd.size(); i++)
		{
			char c = cmd[i];
			if (c == 'S')
			{
				// 3, 4?????????????????????
				int tmpF = F;
				F = N;
				N = B;
				B = S;
				S = tmpF;
			}
			else if (c == 'N')
			{
				// 3, 4?????????????????????
				int tmpN = N;
				N = F;
				F = S;
				S = B;
				B = tmpN;
			}
			else if (c == 'E')
			{
				// 2,5?????????????????????
				int tmpB = B;
				B = E;
				E = F;
				F = W;
				W = tmpB;
			}
			else if (c == 'W')
			{
				int tmpW = W;
				W = F;
				F = E;
				E = B;
				B = tmpW;
			}
		}
	}
	int GetFront()
	{
		return F;
	}
	int GetLabel()
	{
		return label[F-1];
	}
	int GetSouthLabel()
	{
		return label[S-1];
	}
	int GetEastLabel()
	{
		return label[E-1];
	}
	int GetWestLabel()
	{
		return label[W-1];
	}
	int GetBackLabel()
	{
		return label[B-1];
	}
	int GetNorthLabel()
	{
		return label[N-1];
	}

	int IsSameDice(Dice &d)
	{
		if((d.GetLabel() == this->GetLabel())
			&& (d.GetSouthLabel() == this->GetSouthLabel())
			&& (d.GetEastLabel() == this->GetEastLabel())
			&& (d.GetWestLabel() == this->GetWestLabel())
			&& (d.GetBackLabel() == this->GetBackLabel())
			&& (d.GetNorthLabel() == this->GetNorthLabel())
//			&& (d.N == this->N && d.E == this->E && d.S == this->S
//				&& d.W == this->W && d.F == this->F && d.B == this->B)
		)
		{
			//cout << "IsSameDice!!" << endl;
			return 1;
		}
		return 0;
	}
	int ThrowTo(Dice &d)
	{
		for (int x = 0; x < 4; x++)
		{
			Reset();
			if (x == 0)
			{
			}
			else if (x == 1)
			{
				string cmd1 = "WSE";
				Run(cmd1);
			}
			else if (x == 2)
			{
				string cmd2 = "WSSE";
				Run(cmd2);
			}
			else if (x == 3)
			{
				string cmd3 = "WSSSE";
				Run(cmd3);
			}
			for (int w = 0; w < 4; w++)
			{
				for (int n = 0; n < 4; n++)
				{
					string nnnn = "N";
					Run(nnnn);
					if (IsSameDice(d))
						return 1;
				}
				string wwww = "W";
				Run(wwww);
			}
		}
		return 0;
	}
	// ?????°??????????????§N?????????W????????????
	int ThrowTo(int argF, int argS)
	{
		//cout << "DEBUG:Begin ThrowTo(int argF, int argS)" << endl;
		for (int x = 0; x < 4; x++)
		{
			Reset();
			if (x == 0)
			{
			}
			else if (x == 1)
			{
				string cmd1 = "WSE";
				Run(cmd1);
			}
			else if (x == 2)
			{
				string cmd2 = "WSSE";
				Run(cmd2);
			}
			else if (x == 3)
			{
				string cmd3 = "WSSSE";
				Run(cmd3);
			}
			for (int w = 0; w < 4; w++)
			{
				for (int n = 0; n < 4; n++)
				{
					string nnnn = "N";
					Run(nnnn);
					//printf("inArg(%d,%d)   dice[%d,%d]\n", argF, argS, GetLabel(), GetSouthLabel());
					if (GetLabel() == argF && GetSouthLabel() == argS)
					{
						//cout << "HIT:" << label[E-1] << endl;
						return label[E-1];
					}
				}
				string wwww = "W";
				Run(wwww);
			}
		}
		return 1;
	}
	
public:
	int N;
	int E;
	int S;
	int W;
	int F;
	int B;
private:
	unsigned int label[6];
};

int main()
{
	int n;
	cin >> n;
	vector<Dice> ary;
	
	for (int i = 0; i < n; i++)
	{
		unsigned int in1[6] = {0};
		for (int j = 0; j < 6; j++)
		{
			cin >> in1[j];
		}
		
		Dice dice(in1);
		ary.push_back(dice);
		//cout << "push:" << i << endl;
	}
	//cout << "vec size=" << ary.size() << endl;
	
	int sameFlag = 0;
	if (n == 2)
	{
		// ???????????????????????¨??????
		if (ary[0].ThrowTo(ary[1]))
			sameFlag = 1;
	}
	else
	{
		for (int i = 0; i< n; i++)
		{
			for (int j = i+1; j < n-1; j++)
			{
				// ???????????????????????¨??????
				if (ary[i].ThrowTo(ary[j]))
				{
					//cout << "i=" << i << ",j=" << j << endl;
					sameFlag = 1;
					break;
				}
			}
			if (sameFlag == 1)
				break;
		}
	}
		// ???????????°????????´???"YES"
	cout << ((sameFlag == 0) ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 1224