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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ITP1_11_D();
        }

        static bool Same(Dice dice1, Dice dice2)
        {
            var flag = false;

            for (int i = 0; i < 3; i++)
            {
                // ①A: Dice1.Top を Dice2.Top に合わせる 
                for (int n = 0; n < 3; n++)
                {
                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.East);

                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.South);
                }

                // ②A: Dice1.Front を Dice2.Front に合わせる
                if (flag)
                {
                    flag = false;

                    for (int n = 0; n < 4; n++)
                    {
                        if (dice1.Front == dice2.Front)
                        {
                            flag = true;
                            break;
                        }
                        dice1.Roll(Direction.Right);
                    }
                }

                // ③A: 全体が一致すれば真
                if (flag &&
                    dice1.Top == dice2.Top &&
                    dice1.Bottom == dice2.Bottom &&
                    dice1.Right == dice2.Right &&
                    dice1.Left == dice2.Left &&
                    dice1.Front == dice2.Front &&
                    dice1.Back == dice2.Back)
                {
                    return true;
                }

                dice2.Roll(Direction.East);

                // ①B: Dice1.Top を Dice2.Top に合わせる 
                for (int n = 0; n < 3; n++)
                {
                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.East);

                    if (dice1.Top == dice2.Top)
                    {
                        flag = true;
                        break;
                    }
                    dice1.Roll(Direction.South);
                }

                // ②B: Dice1.Front を Dice2.Front に合わせる
                if (flag)
                {
                    flag = false;

                    for (int n = 0; n < 4; n++)
                    {
                        if (dice1.Front == dice2.Front)
                        {
                            flag = true;
                            break;
                        }
                        dice1.Roll(Direction.Right);
                    }
                }

                // ③B: 全体が一致すれば真
                if (flag &&
                    dice1.Top == dice2.Top &&
                    dice1.Bottom == dice2.Bottom &&
                    dice1.Right == dice2.Right &&
                    dice1.Left == dice2.Left &&
                    dice1.Front == dice2.Front &&
                    dice1.Back == dice2.Back)
                {
                    return true;
                }

                dice2.Roll(Direction.South);
            }

            return false;
        }

        static void ITP1_11_D()
        {
            var diceCount = int.Parse(Console.ReadLine());
            var diceList = new List<Dice>();

            for (int i = 0; i < diceCount; i++)
            {
                diceList.Add(new Dice(
                    Console.ReadLine()
                    .Split(' ')
                    .Select(x => int.Parse(x))
                    .ToArray()));
            }

            var count = 0;

            foreach (var dice in diceList)
            {
                for (int i = 0; i < diceCount; i++)
                {
                    if (!Same(dice, diceList[i]))
                    {
                        count++;
                    }
                }
            }

            if (count != 0 && count % diceCount == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }

    /// <summary>
    /// 方角を示します。
    /// </summary>
    public enum Direction
    {
        North,
        East,
        South,
        West,
        Right,
        Left
    }

    public class Dice
    {
        #region Public Property

        /// <summary>
        /// サイコロの上面の要素を取得します。
        /// </summary>
        public int Top
        {
            get { return DiceList[0, 0]; }
            private set { DiceList[0, 0] = value; }
        }
        /// <summary>
        /// サイコロの下面の要素を取得します。
        /// </summary>
        public int Bottom
        {
            get { return DiceList[2, 0]; }
            private set { DiceList[2, 0] = value; }
        }

        /// <summary>
        /// サイコロの左面の要素を取得します。
        /// </summary>
        public int Left
        {
            get { return DiceList[0, 3]; }
            private set { DiceList[0, 3] = value; }
        }

        /// <summary>
        /// サイコロの右面の要素を取得します。
        /// </summary>
        public int Right
        {
            get { return DiceList[0, 1]; }
            private set { DiceList[0, 1] = value; }
        }

        /// <summary>
        /// サイコロの前面の要素を取得します。
        /// </summary>
        public int Front
        {
            get { return DiceList[1, 0]; }
            private set { DiceList[1, 0] = value; }
        }

        /// <summary>
        /// サイコロの後面の要素を取得します。
        /// </summary>
        public int Back
        {
            get { return DiceList[3, 0]; }
            private set { DiceList[3, 0] = value; }
        }

        public int[,] DiceList { get; private set; }

        #endregion

        public Dice(int[] face)
        {
            DiceList = new int[4, 4];

            DiceList[0, 0] = face[0];
            DiceList[1, 0] = face[1];
            DiceList[2, 0] = face[5]; //
            DiceList[3, 0] = face[4];

            DiceList[0, 1] = face[2];
            DiceList[0, 2] = face[5]; //
            DiceList[0, 3] = face[3];
        }

        /// <summary>
        /// 方角を指定してサイコロを転がします、
        /// </summary>
        public void Roll(Direction direction)
        {
            switch (direction)
            {
                case Direction.North:
                    RollNorth();
                    break;

                case Direction.East:
                    RollEast();
                    break;

                case Direction.South:
                    RollSouth();
                    break;

                case Direction.West:
                    RollWest();
                    break;

                case Direction.Right:
                    RoolRight();
                    break;

                case Direction.Left:
                    RoolLeft();
                    break;
            }
        }

        #region Private Method

        /// <summary>
        /// 横方向の変更を縦方向に反映します。
        /// </summary>
        private void UpdateXtoY() => DiceList[2, 0] = DiceList[0, 2];

        /// <summary>
        /// 縦方向の変更を横方向に反映します。
        /// </summary>
        private void UpdateYtoX() => DiceList[0, 2] = DiceList[2, 0];

        /// <summary>
        /// 北方向へ回転します。
        /// </summary>
        private void RollNorth()
        {
            var tmp = DiceList[0, 0];

            for (int i = 0; i < 3; i++)
            {
                DiceList[i, 0] = DiceList[i + 1, 0];
            }

            DiceList[3, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 南方向へ回転します。
        /// </summary>
        private void RollSouth()
        {
            var tmp = DiceList[3, 0];

            for (int i = 3; i > 0; i--)
            {
                DiceList[i, 0] = DiceList[i - 1, 0];
            }

            DiceList[0, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 東方向へ回転します。
        /// </summary>
        private void RollEast()
        {
            var tmp = DiceList[0, 3];

            for (int i = 3; i > 0; i--)
            {
                DiceList[0, i] = DiceList[0, i - 1];
            }

            DiceList[0, 0] = tmp;
            UpdateXtoY();
        }

        /// <summary>
        /// 西方向へ回転します。
        /// </summary>
        private void RollWest()
        {
            var tmp = DiceList[0, 0];

            for (int i = 0; i < 3; i++)
            {
                DiceList[0, i] = DiceList[0, i + 1];
            }

            DiceList[0, 3] = tmp;
            UpdateXtoY();
        }

        /// <summary>
        /// 右方向へ回転します。
        /// </summary>
        private void RoolRight()
        {
            var tmp = Front;
            Front = Left;
            Left = Back;
            Back = Right;
            Right = tmp;
        }

        /// <summary>
        /// 左方向へ回転します。
        /// </summary>
        private void RoolLeft()
        {
            var tmp = Front;
            Front = Right;
            Right = Back;
            Back = Left;
            Left = tmp;
        }

        #endregion
    }
}



Measured memory_bytes: 18452