using System;
using System.Collections.Generic;
using System.Linq;

namespace Aizu
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var diceList = new Dictionary<string, List<Dice>>();

            // さいころを作成し、構成する数値が同じもの同士でまとめる
            for(int i = 0; i < n; i++)
            {
                var diceValue = Console.ReadLine();
                var dice = new Dice(diceValue);

                // 同じ数値の数を構成しているさいころでまとめる
                var diceValueSort = string.Join(" ", (string[])diceValue.Split(' ').OrderBy(d => d).ToArray());

                if (!diceList.ContainsKey(diceValueSort))
                {
                    diceList.Add(diceValueSort, new List<Dice>());
                }

                diceList[diceValueSort].Add(dice);
            }

            // 全て一致しないことをチェック
            var flag = false;
            foreach(string key in diceList.Keys)
            {
                // 同じ数値(個数)が一致するさいころが一つしかない場合は、一致しようがないので次のサイコロ
                if(diceList[key].Count < 2) { continue; }

                for(int i = 0; i < diceList[key].Count; i++)
                {
                    for(int j = i + 1; j < diceList[key].Count; j++)
                    {
                        flag = Dice.Judge(diceList[key][i], diceList[key][j]);
                        if (flag) {
                            break;
                        }
                    }

                    if (flag) { break; }
                }

                if (flag) { break; }
            }

            Console.WriteLine(flag ? "No" : "Yes");
        }
    }

    class Dice
    {
        public int Top { get; private set; }
        public int Bottom { get; private set; }
        public int Right { get; private set; }
        public int Left { get; private set; }
        public int Front { get; private set; }
        public int Back { get; private set; }
        public int[] AllValue { get; set; }

        public Dice(string value)
        {
            var temp = value.Split(' ');
            this.Top = int.Parse(temp[0]);
            this.Front = int.Parse(temp[1]);
            this.Right = int.Parse(temp[2]);
            this.Left = int.Parse(temp[3]);
            this.Back = int.Parse(temp[4]);
            this.Bottom = int.Parse(temp[5]);

            this.AllValue = new int[] { this.Top, this.Front, this.Right, this.Left, this.Back, this.Bottom };
        }
 
        /// <summary>
        /// 受け取ったダイスのTopとBottomに一致する箇所を調べその時の側面が一致するかチェックする
        /// </summary>
        /// <param name="dice">比較対象のダイス</param>
        /// <returns>True:一致, False:不一致</returns>
        public static bool Judge(Dice dice1, Dice dice2)
        {
            bool judge = false;
            int[] diceSide = new int[] { dice1.Front, dice1.Right, dice1.Back, dice1.Left };

            // Top, Bottom
            if (dice1.Top == dice2.Top && dice1.Bottom == dice2.Bottom)
            {
                int[] thisDiceSide = new int[] { dice2.Front, dice2.Right, dice2.Back, dice2.Left };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Bottom, Top
            if (dice1.Top == dice2.Bottom && dice1.Bottom == dice2.Top)
            {
                int[] thisDiceSide = new int[] { dice2.Front, dice2.Left, dice2.Back, dice2.Right };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Right, Left
            if (dice1.Top == dice2.Right && dice1.Bottom == dice2.Left)
            {
                int[] thisDiceSide = new int[] { dice2.Front, dice2.Bottom, dice2.Back, dice2.Top };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Left, Right
            if (dice1.Top == dice2.Left && dice1.Bottom == dice2.Right)
            {
                int[] thisDiceSide = new int[] { dice2.Front, dice2.Top, dice2.Back, dice2.Bottom };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Front, Back
            if (dice1.Top == dice2.Front && dice1.Bottom == dice2.Back)
            {
                int[] thisDiceSide = new int[] { dice2.Bottom, dice2.Right, dice2.Top, dice2.Left };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            // Back, Front
            if (dice1.Top == dice2.Back && dice1.Bottom == dice2.Front)
            {
                int[] thisDiceSide = new int[] { dice2.Bottom, dice2.Left, dice2.Top, dice2.Right };
                judge = JudgeSide(diceSide, thisDiceSide);
            }

            return judge;
        }

        /// <summary>
        /// 側面を比較する
        /// </summary>
        /// <param name="dice1">さいころ１</param>
        /// <param name="dice2">さいころ２</param>
        /// <returns>true:同じ配置のさいころ, false:配置がことなるさいころ</returns>
        private static bool JudgeSide(int[] dice1, int[] dice2)
        {
            for(int ds = 0; ds < 4; ds++)
            {
                int start = 0;
                for(int tds = start; tds < 4; tds++)
                {
                    if(dice1[ds % 4] == dice2[tds % 4] 
                        && dice1[(ds + 1) % 4] == dice2[(tds + 1) % 4]
                        && dice1[(ds + 2) % 4] == dice2[(tds + 2) % 4]
                        && dice1[(ds + 3) % 4] == dice2[(tds + 3) % 4])
                    {
                        return true;
                    }

                    start++;
                }
            }
            
            return false;
        }
    }
}



Measured memory_bytes: 10712