using System;
using System.Collections;

namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputN = int.Parse(Console.ReadLine());
            ArrayList data = new ArrayList();
            string bn = null;
            int kari = 0;
            int count = 0;
            for (int i = 0; i < inputN; i++)
            {
                string[] sai = Console.ReadLine().Split(' ');
                int sai0 = int.Parse(sai[0]);
                int sai1 = int.Parse(sai[1]);
                int sai2 = int.Parse(sai[2]);
                int sai3 = int.Parse(sai[3]);
                int sai4 = int.Parse(sai[4]);
                int sai5 = int.Parse(sai[5]);

                if (i != 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        string s = data[j].ToString();
                        string s0 = s[0].ToString();
                        string s1 = s[1].ToString();
                        string s2 = s[2].ToString();
                        string s3 = s[3].ToString();
                        string s4 = s[4].ToString();
                        string s5 = s[5].ToString();

                        int sai_0 = int.Parse(s0);
                        int sai_1 = int.Parse(s1);
                        int sai_2 = int.Parse(s2);
                        int sai_3 = int.Parse(s3);
                        int sai_4 = int.Parse(s4);
                        int sai_5 = int.Parse(s5);


                        if ((sai_0 == sai3 || sai_0 == sai2) && (sai_5 == sai3 || sai_5 == sai2))
                        {
                            kari = sai1;
                            sai1 = sai2;
                            sai2 = sai4;
                            sai4 = sai3;
                            sai3 = kari;
                        }
                        for (int k = 0; k < 3; k++)
                        {
                            if (sai0 == sai_0 && sai5 == sai_5)
                            {
                                break;
                            }
                            else
                            {
                                kari = sai0;
                                sai0 = sai1;
                                sai1 = sai5;
                                sai5 = sai4;
                                sai4 = kari;
                            }
                        }
                        for (int k = 0; k < 3; k++)
                        {
                            if (sai1 == sai_1 && sai4 == sai_4)
                            {
                                break;
                            }
                            else
                            {
                                kari = sai1;
                                sai1 = sai2;
                                sai2 = sai4;
                                sai4 = sai3;
                                sai3 = kari;
                            }
                        }
                        if (sai0 == sai_0 && sai0 == sai_0 && sai1 == sai_1 && sai2 == sai_2 && sai3 == sai_3 && sai4 == sai_4 && sai5 == sai_5)
                            count += 1;
                    }
                }
                bn = sai0.ToString() + sai1.ToString() + sai2.ToString() + sai3.ToString() + sai4.ToString() + sai5.ToString();
                data.Add(bn);
            }
            if (count == 0)
                Console.WriteLine("Yes");
            else if (count != 0)
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 9452