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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            //入力読取。
            string strDate = Console.ReadLine();
            int intDate = int.Parse(strDate);
            List<string> diceList = new List<string>();
            for(int date = 0; date < intDate; date++){
                string strDice = Console.ReadLine();
                diceList.Add(strDice);
            }
            
            //サイコロのクラスにて処理。
            string strAnsewr = "";
            for(int first = 0; first < intDate - 1; first++){
                for(int second = first + 1; second < intDate; second++){
                    Dice insD = new Dice(diceList[first], diceList[second]);
                    strAnsewr = insD.GetAnswer();
                    if(strAnsewr == "No"){
                        break;
                    }
                }
                if(strAnsewr == "No"){
                    break;
                }
            }
            
            //出力
            Console.WriteLine(strAnsewr);
            
        }
        
    }
    
    class Dice{
        
        private string strDice;
        private string strDice2;
        private int[] dice;
        private int[] dice2;
        private string strAnsewr;
        
        public Dice(string strDice, string strDice2){
            this.strDice = strDice;
            this.strDice2 = strDice2;
            SetDice();
        }
        
        private void SetDice(){
        
            //サイコロ生成。
            this.dice = MakeDice(strDice);
            this.dice2 = MakeDice(strDice2);
            
            //サイコロを転がす。
            string strOrder = "NNNNWNNNWNNNENNNENNNWNNN";
            char[] chOrder = strOrder.ToCharArray();
            this.strAnsewr = "Yes";
            for(int order = 0; order < chOrder.Length; order++){
                Roll(chOrder[order]);
                bool blEquals = dice.SequenceEqual(dice2);
                if(blEquals){
                    this.strAnsewr = "No";
                    break;
                }
            }
            
        }
        
        private int[] MakeDice(string strDiceTemp){
            
            string[] strDiceArray = strDiceTemp.Split(' ');
            int[] diceTemp = new int[6];
            for(int index = 0; index < 6; index++){
                diceTemp[index] = int.Parse(strDiceArray[index]);
            }
            return diceTemp;
            
        }
        
        private void Roll(char chDirection){
            if(chDirection == 'N'){
                int intTemp = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[4];
                dice[4] = intTemp;
            }else if(chDirection == 'W'){
                int intTemp = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[3];
                dice[3] = intTemp;
            }else if(chDirection == 'E'){
                int intTemp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[2];
                dice[2] = intTemp;
            }else{
                int intTemp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[5];
                dice[5] = dice[1];
                dice[1] = intTemp;
            }
        }
        
        public string GetAnswer(){
            return strAnsewr;
        }
        
    }

}



Measured memory_bytes: 22276