using System;

namespace ITP1_11_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dice[] numbers = new Dice[n];
            string result = null;

            for (int i = 0; i < n; i++)
            {
                int[] number = new int[6];
                string[] input = Console.ReadLine().Split(' ');
                for (int j = 0; j < 6; j++)
                    number[j] = int.Parse(input[j]);  //intに変換

                Dice tmp = new Dice(number);
                numbers[i] = tmp;
            }
            
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    result = numbers[i].Hantei(numbers[j]);
                    if (result == "No")
                        break;
                }
                if (result == "No")
                    break;
            }
            if (result == "No")
                Console.WriteLine("No");
            if (result == "Yes")
                Console.WriteLine("Yes");
        }
    }

    class Dice
    {
        public int[] D;
        public Dice(int[] data)
        {
            D = data;
        }
        public void Kaiten()
        {
            int D1, D2, D4, D3;
            D1 = this.D[1];
            D2 = this.D[2];
            D3 = this.D[3];
            D4 = this.D[4];
            this.D[1] = D2;
            this.D[2] = D4;
            this.D[4] = D3;
            this.D[3] = D1;
        }
        public void ToE()
        {
            int D0, D2, D5, D3;
            D0 = this.D[0];
            D2 = this.D[2];
            D3 = this.D[3];
            D5 = this.D[5];
            this.D[0] = D3;
            this.D[2] = D0;
            this.D[3] = D5;
            this.D[5] = D2;
        }
        public void ToN()
        {
            int D1, D0, D4, D5;
            D1 = this.D[1];
            D0 = this.D[0];
            D5 = this.D[5];
            D4 = this.D[4];
            this.D[0] = D1;
            this.D[1] = D5;
            this.D[4] = D0;
            this.D[5] = D4;
        }
        public void ToS()
        {
            int D1, D0, D4, D5;
            D1 = this.D[1];
            D0 = this.D[0];
            D5 = this.D[5];
            D4 = this.D[4];
            this.D[0] = D4;
            this.D[1] = D0;
            this.D[4] = D5;
            this.D[5] = D1;
        }
        public void ToW()
        {
            int D0, D2, D5, D3;
            D0 = this.D[0];
            D2 = this.D[2];
            D3 = this.D[3];
            D5 = this.D[5];
            this.D[0] = D2;
            this.D[2] = D5;
            this.D[5] = D3;
            this.D[3] = D0;
        }

        public void Indata(int[] data)
        {
            this.D[0] = data[0];
            this.D[1] = data[1];
            this.D[2] = data[2];
            this.D[3] = data[3];
            this.D[4] = data[4];
            this.D[5] = data[5];
        }

        public int Sum()
        {
            int sum;
            sum = this.D[0] + this.D[1] + this.D[2] + this.D[3] + this.D[4] + this.D[5];
            return sum;
        }

        public string Hantei(Dice saikoro)
        {
            string yes = "Yes";
            string no = "No";
            string result = null;

            if(this.Sum()!=saikoro.Sum())
            {
                result = yes;
                return result;
            }

            //上面合わせ
            if (saikoro.D[1] == this.D[0])
            {
                saikoro.ToN();
            }
            if (saikoro.D[2] == this.D[0])
            {
                saikoro.ToW();
            }
            if (saikoro.D[3] == this.D[0])
            {
                saikoro.ToE();
            }
            if (saikoro.D[4] == this.D[0])
            {
                saikoro.ToS();
            }
            if (saikoro.D[5] == this.D[0])
            {
                saikoro.ToN();
                saikoro.ToN();
            }
            //上面合わせここまで

            //下面チェック
            if (saikoro.D[5] != this.D[5])
            {
                result = yes;
                return result;
            }

            //前面合わせ
            for (int i = 0; i < 4; i++)
            {
                if (saikoro.D[1] != this.D[1])
                    saikoro.Kaiten();
                if (saikoro.D[1] == this.D[1])
                    break;
                if(i==3)
                {
                    result = yes;
                    return result;
                }
            }

            //前面合わせここまで
            //背面チェック
            if (saikoro.D[4] != this.D[4])
            {
                result = yes;
                return result;
            }
            //右面チェック
            if (saikoro.D[2] != this.D[2])
            {
                result = yes;
                return result;
            }
            else
                result = no;

            return result;
        }
    }
}



Measured memory_bytes: 7884