using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        enum Directoin
        {
            N,
            E,
            W,
            S,
            U,
            D,
        }

        class Dice
        {
            private int[] nums = new int[6];
            private List<Directoin> dirs;
            public Dice(IEnumerable<int> nums)
            {
                this.nums = nums.ToArray();
                dirs = new List<Directoin>()
                {
                    Directoin.U,
                    Directoin.S,
                    Directoin.E,
                    Directoin.W,
                    Directoin.N,
                    Directoin.D,
                };
            }
            public void Roll(Directoin roll)
            {
                switch (roll)
                {
                    case Directoin.N:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.S;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.W;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.E;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.S:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.N;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public void Rotate(Directoin rotate)
            {
                switch (rotate)
                {
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public int Getnum(Directoin dir)
            {
                return nums[dirs.IndexOf(dir)];
            }
            public override int GetHashCode()
            {
                var result = 17;
                foreach (var dir in Enum.GetValues(typeof(Directoin)).Cast<Directoin>())
                {
                    result = 100 * result + Getnum(dir);
                }
                return result;
            }
            public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return false;
                }
                var c = obj as Dice;
                if (c == null)
                {
                    return false;
                }
                return GetHashCode() == c.GetHashCode();
            }
        }

        static void Main(string[] args)
        {
            var N = GetNumber();

            var rolls = new[]
            {
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.W,
                Directoin.W,
                Directoin.W,
            };
            var rotates = new[]
            {
                Directoin.W,
                Directoin.W,
                Directoin.W,
                Directoin.W
            };

            var numList = new List<int[]>();
            for (int i = 0; i < N; i++)
            {
                numList.Add(GetNumbersInt());
            }

            for (int i = 0; i < N - 1; i++)
            {
                var dice1 = new Dice(numList[i]);
                var top = dice1.Getnum(Directoin.U);

                for (int j = i + 1; j < N; j++)
                {
                    var dice2 = new Dice(numList[j]);

                    foreach (var roll in rolls)
                    {
                        dice2.Roll(roll);
                        if (dice2.Getnum(Directoin.U) == top)
                        {
                            break;
                        }
                    }
                    foreach (var rotate in rotates)
                    {
                        dice2.Rotate(rotate);
                        if (dice2.Equals(dice1))
                        {
                            System.Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }

            System.Console.WriteLine("Yes");
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 10332