using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Dice_III
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dice[] dice = new Dice[n];
            for (int i = 0; i < n; ++i)
            {
                var input = Console.ReadLine().Split(' ');
                dice[i] = new Dice(input);
                for (int j = 0; j < 6; ++j)
                {
                    dice[i][j] = int.Parse(input[j]);
                }
            }

            for (int i = 0; i < n - 1; ++i)
            {
                for (int j = i + 1; j < n; ++j)
                {
                    if (Is_Dice_Equal(ref dice[i], ref dice[j]))
                    {
                        Console.WriteLine("No");
                        Environment.Exit(0);
                    }
                }
            }
            Console.WriteLine("Yes");
        }

        //(??????)????????§???
        static bool Check(Dice[] dice, int depth)
        {
            if (dice.Length <= 1)
            {
                Console.WriteLine("?????§????????¨??????");
                Environment.Exit(-1);
            }
            if (depth + 1 == dice.Length)
            {
                return true;
            }
            for (int i = depth + 1; i < dice.Length; ++i)
            {
                if (!Is_Dice_Equal(ref dice[i - 1], ref dice[i]))
                {
                    return false;
                }
            }
            return Check(dice,depth + 1);
        }

        static bool Is_Dice_Equal(ref Dice a, ref Dice b)
        {
            if ((a[0] == b[2] || a[0] == b[3]) && (a[5] == b[2] || a[5] == b[3]))
            {
                var work = b[1];
                b[1] = b[2];
                b[2] = b[4];
                b[4] = b[3];
                b[3] = work;
            }
            for (int i = 0; i < 3; ++i)
            {
                if ((a[0] == b[0]) && (a[5] == b[5])) break;
                b.Rotation('N');
            }// End_for
            for (int i = 0; i < 3; ++i)
            {
                if ((a[1] == b[1]) && (a[4] == b[4])) break;
                var work = b[1];
                b[1] = b[2];
                b[2] = b[4];
                b[4] = b[3];
                b[3] = work;
            }// End_for
            return Check_Dice(a, b);
        }

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


    class Dice
    {
        public int[] surface;

        public Dice()
        {
            Console.WriteLine("???????????\????????????");
            Environment.Exit(-1);
        }
        public Dice(String[] str)
        {
            surface = new int[6];
            for (int i = 0; i < 6; ++i)
            {
                this.surface[i] = int.Parse(str[i]);
            }
        }// End_Constructor
        public Dice(int[] input)
        {
            for (int i = 0; i < 6; ++i)
            {
                this.surface[i] = input[i];
            }
        }// End_Constructor

        //(??????)????????§???
        public int[] Get_Surface()
        {
            return this.surface;
        }
        public int Get_Surface(int n)
        {
            return this.surface[n];
        }

        //???????????????(private?????????????????????????????§??????public????\????????????????)
        public int this[int n]
        {
            get
            {
                return this.surface[n];
            }
            set
            {
                this.surface[n] = value;
            }
        }

        public void Rotation(char c)
        {
            switch (c)
            {
                case 'E':
                    this.Rotation_E();
                    break;
                case 'N':
                    this.Rotation_N();
                    break;
                case 'S':
                    this.Rotation_S();
                    break;
                case 'W':
                    this.Rotation_W();
                    break;
                default:
                    Console.WriteLine("??\?????¨???????");
                    Environment.Exit(-1);
                    break;
            }
        }// End_Rotation

        private void Rotation_E()
        {
            this.Rotation_Run(0, 3, 5, 2);
        }

        private void Rotation_N()
        {
            this.Rotation_Run(0, 1, 5, 4);
        }

        private void Rotation_S()
        {
            this.Rotation_Run(0, 4, 5, 1);
        }
        private void Rotation_W()
        {
            this.Rotation_Run(0, 2, 5, 3);
        }

        static void Swap(ref int a, ref int b)
        {
            var t = a;
            a = b;
            b = t;
        }

        void Rotation_Run(int a, int b, int c, int d)
        {
            var work = this.surface[a];
            this.surface[a] = this.surface[b];
            this.surface[b] = this.surface[c];
            this.surface[c] = this.surface[d];
            this.surface[d] = work;
        }// End_Rotation_Run

        public int Right_Surface(int a, int b)
        {
            if (a == this.surface[0])
            {
                if (b == this.surface[1]) return this.surface[2];
                if (b == this.surface[2]) return this.surface[4];
                if (b == this.surface[3]) return this.surface[1];
                if (b == this.surface[4]) return this.surface[3];
            }
            else if (a == this.surface[1])
            {
                if (b == this.surface[0]) return this.surface[3];
                if (b == this.surface[2]) return this.surface[0];
                if (b == this.surface[3]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[2];
            }
            else if (a == this.surface[2])
            {
                if (b == this.surface[0]) return this.surface[1];
                if (b == this.surface[1]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[4];
                if (b == this.surface[4]) return this.surface[0];
            }
            else if (a == this.surface[3])
            {
                if (b == this.surface[0]) return this.surface[4];
                if (b == this.surface[1]) return this.surface[0];
                if (b == this.surface[4]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[1];
            }
            else if (a == this.surface[4])
            {
                if (b == this.surface[0]) return this.surface[2];
                if (b == this.surface[2]) return this.surface[5];
                if (b == this.surface[3]) return this.surface[0];
                if (b == this.surface[5]) return this.surface[3];
            }
            else if (a == this.surface[5])
            {
                if (b == this.surface[1]) return this.surface[3];
                if (b == this.surface[2]) return this.surface[1];
                if (b == this.surface[3]) return this.surface[4];
                if (b == this.surface[4]) return this.surface[2];
            }
            else
            {
                Console.WriteLine("???????????????");
                return -1;
            }
            return -1;
        }// End_Right_Surface
    }// End_CLass
}


Measured memory_bytes: 8988