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

namespace ITP1_11_D
{
    class Program
    {


        public static IEnumerable<string[]> ReadSplitWords(Func<string> reader, char splitChar)
        {
            while (true)
            {
                yield return reader().Split(splitChar);
            }
        }


        public static bool HasDuplicate<T>(IEnumerable<T> stream, Func<T, T, bool> isEquals)
        {
            Func<T, bool> recursiveFunction = _ => false;

            foreach (var n in stream) {
                if (recursiveFunction(n)) 
                {
                    return true;
                }

                var currentFunc = recursiveFunction;
                recursiveFunction = (m) => isEquals(m, n) || currentFunc(m);
            }

            return false;
        }


        public static void Main(string[] args)
        {
            var count = int.Parse(Console.ReadLine());

            // (1)
            //var alias = ReadSplitWords(Console.ReadLine, ' ').Take(count).ToArray();
            //var hasDuplicate = HasDuplicate(alias, Dice.EqualsAliasOfDice);


            // (2)
            var hasDuplicate = false;
            var diceAliasList = new string[count][];
            for (var i = 0; i < count; ++i)
            {
                var alias = Console.ReadLine().Split(' ');
                for (var h = 0; h < i; ++h) 
                {
                    if (Dice.EqualsAliasOfDice(alias, diceAliasList[h])) 
                    {
                        hasDuplicate = true;
                        break;
                    }
                }

                if (hasDuplicate == true)
                {
                    break;
                }
                diceAliasList[i] = alias;
            }

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

    class Dice
    {
        public Dice()
        {
            Top = 0;
            Front = 1;
            Right = 2;
        }

        public void RotateNorth()
        {
            var temp = Inverse(Top);
            Top = Front;
            Front = temp;
        }


        public void RotateSouth()
        {
            var temp = Inverse(Front);
            Front = Top;
            Top = temp;
        }


        public void RotateEast()
        {
            var temp = Inverse(Right);
            Right = Top;
            Top = temp;
        }


        public void RotateWest()
        {
            var temp = Inverse(Top);
            Top = Right;
            Right = temp;
        }


        public enum Surface { TOP, BOTTOM, FRONT, BACK, RIGHT, LEFT, NONE }

        public Surface Match(int surface)
        {
            if (surface == Top) return Surface.TOP;
            if (surface == Bottom) return Surface.BOTTOM;
            if (surface == Front) return Surface.FRONT;
            if (surface == Back) return Surface.BACK;
            if (surface == Right) return Surface.RIGHT;
            if (surface == Left) return Surface.LEFT;

            return Surface.NONE;
        }


        public bool RotateToTop(int top)
        {
            switch (Match(top))
            {
                case Surface.TOP: break;
                case Surface.BOTTOM: RotateNorth(); RotateNorth(); break;
                case Surface.FRONT: RotateNorth(); break;
                case Surface.BACK: RotateSouth(); break;
                case Surface.RIGHT: RotateWest(); break;
                case Surface.LEFT: RotateEast(); break;
            }

            return Top == top;
        }


        public bool RotateToTopAndFront(int top, int front)
        {
            if (RotateToTop(top) == false)
            {
                return false;
            }

            switch (Match(front))
            {
                case Surface.RIGHT: RotateRightOfZCoords(); break;
                case Surface.BACK: RotateRightOfZCoords(); RotateRightOfZCoords(); break;
                case Surface.LEFT: RotateLeftOfZCoords(); break;
            }

            return Top == top && Front == front;
        }


        public void RotateRightOfZCoords()
        {
            var temp = Back;
            Front = Right;
            Right = temp;
        }


        public void RotateLeftOfZCoords()
        {
            var temp = Left;
            Right = Front;
            Front = temp;
        }



        public int RightOf(int front)
        {
            switch (Match(front))
            {
                case Surface.FRONT: return Right;
                case Surface.RIGHT: return Back;
                case Surface.BACK: return Left;
                case Surface.LEFT: return Front;
            }
            return -1;
        }


        public int Top { get; private set; }


        public int Front { get; private set; }


        public int Right { get; private set; }


        public int Bottom { get { return Inverse(Top); } }


        public int Back { get { return Inverse(Front); } }


        public int Left { get { return Inverse(Right); } }



        public int Inverse(int surface)
        {
            return 5 - surface;
        }


        public IEnumerable<int> Surfaces()
        {
            yield return Top;
            yield return Front;
            yield return Right;
            yield return Left;
            yield return Back;
            yield return Bottom;
        }


        public static bool EqualsAlias(string[] alias1, Dice dice1, string[] alias2, Dice dice2)
        {
            //var joinedAlias1 = string.Concat(dice1.Surfaces().Select(n => alias1[n]).ToArray());
            //var joinedAlias2 = string.Concat(dice2.Surfaces().Select(n => alias2[n]).ToArray());
            //return joinedAlias1 == joinedAlias2;

            //var orderedAlias1 = dice1.Surfaces().Select(n => alias1[n]);
            //var orderedAlias2 = dice2.Surfaces().Select(n => alias2[n]);
            //return Enumerable.SequenceEqual(orderedAlias1, orderedAlias2);

            if (alias1[dice1.Top] != alias2[dice2.Top]) return false;
            if (alias1[dice1.Front] != alias2[dice2.Front]) return false;
            if (alias1[dice1.Right] != alias2[dice2.Right]) return false;
            if (alias1[dice1.Bottom] != alias2[dice2.Bottom]) return false;
            if (alias1[dice1.Back] != alias2[dice2.Back]) return false;
            if (alias1[dice1.Left] != alias2[dice2.Left]) return false;
            return true;
        }

        public static bool EqualsAliasOfNoDuplication(string[] alias1, string[] alias2)
        {
            var dice1 = new Dice();
            var dice2 = new Dice();

            var top = -1;
            var front = -1;
            for (var i = 0; i < alias1.Length; ++i)
            {
                if (alias1[0] == alias2[i])
                {
                    top = i;
                }
                if (alias1[1] == alias2[i])
                {
                    front = i;
                }
            }

            if (dice2.RotateToTopAndFront(top, front) == false)
            {
                return false;
            }

            return EqualsAlias(alias1, dice1, alias2, dice2);
        }


        public static bool EqualsAliasOfDice(string[] alias1, string[] alias2)
        {
            var dice1 = new Dice();
            var dice2 = new Dice();

            for (var i = 0; i < 6; ++i)
            {
                dice2.RotateToTop(i);
                if (EqualsAlias(alias1, dice1, alias2, dice2)) return true;

                dice2.RotateLeftOfZCoords();
                if (EqualsAlias(alias1, dice1, alias2, dice2)) return true;

                dice2.RotateLeftOfZCoords();
                if (EqualsAlias(alias1, dice1, alias2, dice2)) return true;

                dice2.RotateLeftOfZCoords();
                if (EqualsAlias(alias1, dice1, alias2, dice2)) return true;
            }

            return false;
        }

    }
}

Measured memory_bytes: 17764