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

class Program
{
    static void Main(string[] args)
    {
        List<Dice> diceList = new List<Dice>();

        int diceCount = int.Parse(Console.ReadLine());

        for (int i = 0; i < diceCount; i++)
            diceList.Add(new Dice(Console.ReadLine()));

        int diceMatchCount = 0;

        for(int i = 0; i < diceCount; i++)
            for(int j = 0; j < diceCount; j++)
                if(i != j)
                    if(IsMatchDice(diceList[i], diceList[j]))
                        diceMatchCount++;
        
        Console.WriteLine((diceMatchCount == 0) ? "Yes" : "No");
    }

    /// <summary>
    /// ?????????????????????????????????????¢????
    /// </summary>
    /// <param name="dice1"></param>
    /// <param name="dice2"></param>
    /// <returns></returns>
    private static bool IsMatchDice(Dice dice1, Dice dice2)
    {
        bool isMatch = false;

        char[] direction = new char[2] { 'N', 'E' };

        for (int i = 0; i < direction.Length; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                if (CheckDiceValue(dice1, dice2))
                    isMatch = true;

                dice2.OperationMove(direction[i]);

                for (int k = 0; k < 4; k++)
                {
                    if (CheckDiceValue(dice1, dice2))
                        isMatch = true;

                    dice2.OperationMove('R');
                }
            }
        }

        return isMatch;
    }

    /// <summary>
    /// ?????????????????????????????´?????????????¢????
    /// </summary>
    /// <param name="dice1"></param>
    /// <param name="dice2"></param>
    /// <returns></returns>
    private static bool CheckDiceValue(Dice dice1, Dice dice2)
    {
        bool isMatch = false;

        if (dice1.GetTopNum() == dice2.GetTopNum() &&
            dice1.GetUnderNum() == dice2.GetUnderNum() &&
            dice1.GetLeftNum() == dice2.GetLeftNum() &&
            dice1.GetRightNum() == dice2.GetRightNum() &&
            dice1.GetFrontNum() == dice2.GetFrontNum() &&
            dice1.GetBackNum() == dice2.GetBackNum())
            isMatch = true;

        return isMatch;
    }
}

/// <summary>
/// ??????????????????
/// </summary>
public class Dice
{
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _top;
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _under;
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _left;
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _right;
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _front;
    /// <summary>
    /// ????????????????????????
    /// </summary>
    private int _back;

    /// <summary>
    /// ????????????????????????string
    /// </summary>
    /// <param name="str"></param>
    public Dice(string str)
    {
        int[] ary = str.Split(' ').Select(s => int.Parse(s)).ToArray();

        SetDice(ary);
    }

    /// <summary>
    /// ???????????????????????????
    /// </summary>
    /// <param name="ary"></param>
    private void SetDice(int[] ary)
    {
        _top = ary[0];
        _front = ary[1];
        _right = ary[2];
        _left = ary[3];
        _back = ary[4];
        _under = ary[5];
    }

    /// <summary>
    /// ?????°???????????????????????????????????????(????????????)???
    /// </summary>
    /// <param name="top">??????????????????????????????</param>
    /// <param name="front">??????????????????????????????</param>
    public void AjustDice(int top, int front)
    {
        for (int i = 0; i < 4; i++)
        {
            if (_top == top) break;

            MoveN();
        }

        for (int i = 0; i < 4; i++)
        {
            if (_top == top) break;

            MoveE();
        }

        for (int i = 0; i < 4; i++)
        {
            if (_front == front) break;

            MoveR();
        }
    }

    /// <summary>
    /// ?§??????????
    /// </summary>
    public void OperationMove(char direction)
    {
        switch (direction)
        {
            case 'E': MoveE(); break;
            case 'N': MoveN(); break;
            case 'S': MoveS(); break;
            case 'W': MoveW(); break;
            case 'R': MoveR(); break;
        }
    }

    /// <summary>
    /// E??????????§???????(?????????????????????????????\????????????)
    /// </summary>
    private void MoveE()
    {
        int tmp = _top;
        _top = _left;
        _left = _under;
        _under = _right;
        _right = tmp;
    }
    /// <summary>
    /// N??????????§???????(?????????????????????????????\????????????)
    /// </summary>
    private void MoveN()
    {
        int tmp = _top;
        _top = _front;
        _front = _under;
        _under = _back;
        _back = tmp;
    }
    /// <summary>
    /// S??????????§???????(?????????????????????????????\????????????)
    /// </summary>
    private void MoveS()
    {
        int tmp = _top;
        _top = _back;
        _back = _under;
        _under = _front;
        _front = tmp;
    }
    /// <summary>
    /// W???????§???????(?????????????????????????????\????????????)
    /// </summary>
    private void MoveW()
    {
        int tmp = _top;
        _top = _right;
        _right = _under;
        _under = _left;
        _left = tmp;
    }

    /// <summary>
    /// ????????¢???(?????????????????????????????\????????????)
    /// </summary>
    private void MoveR()
    {
        int tmp = _front;
        _front = _right;
        _right = _back;
        _back = _left;
        _left = tmp;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetTopNum()
    {
        return _top;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetUnderNum()
    {
        return _under;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetLeftNum()
    {
        return _left;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetRightNum()
    {
        return _right;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetFrontNum()
    {
        return _front;
    }

    /// <summary>
    /// ??????????????????????????????????????????
    /// </summary>
    /// <returns></returns>
    public int GetBackNum()
    {
        return _back;
    }
}

Measured memory_bytes: 9588