using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class program{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var dices = new List<Dice>(n);
        for(int i=0; i<n; i++){
            dices.Add(new Dice(Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToList()));
        }

        bool same = false;
        for(int i=0; i<n; i++){
            for(int j=0; j<i; j++){
                //Console.WriteLine($"{i}:{j}:{Dice.SameDice(dices[i],dices[j])}");
                if(Dice.SameDice(dices[i],dices[j])){
                    same = true;
                    break;
                }
            }
            if(same) break;
        }

        if(same){
            Console.WriteLine("No");
        }else{
            Console.WriteLine("Yes");
        }
    }
}

class Dice{
    public List<Face> faces = new List<Face>(6);

    public Dice(List<int> nums){
        faces.Add(new Face(nums[0],'T'));
        faces.Add(new Face(nums[1],'S'));
        faces.Add(new Face(nums[2],'E'));
        faces.Add(new Face(nums[3],'W'));
        faces.Add(new Face(nums[4],'N'));
        faces.Add(new Face(nums[5],'B'));
    }

    public Dice Copy(){
        return new Dice(faces.Select(_ => _.num).ToList());
    }

    public void Rotate(char dir){
        if(dir == 'N'){
            var tmpnum = getFace('T').num;
            getFace('T').num = getFace('S').num;
            getFace('S').num = getFace('B').num;
            getFace('B').num = getFace('N').num;
            getFace('N').num = tmpnum;
        }
        if(dir == 'W'){
            var tmpnum = getFace('T').num;
            getFace('T').num = getFace('E').num;
            getFace('E').num = getFace('B').num;
            getFace('B').num = getFace('W').num;
            getFace('W').num = tmpnum;
        }
        if(dir == 'S'){
            var tmpnum = getFace('T').num;
            getFace('T').num = getFace('N').num;
            getFace('N').num = getFace('B').num;
            getFace('B').num = getFace('S').num;
            getFace('S').num = tmpnum;
        }
        if(dir == 'E'){
            var tmpnum = getFace('T').num;
            getFace('T').num = getFace('W').num;
            getFace('W').num = getFace('B').num;
            getFace('B').num = getFace('E').num;
            getFace('E').num = tmpnum;
        }
    }

    public static void adaptSouth(Dice dice, char dir){
        //sをあわせる
        if(dir == 'N'){
            dice.Rotate('N');
            dice.Rotate('N');
        }
        if(dir == 'T'){
            dice.Rotate('S');
        }
        if(dir == 'E'){
            dice.Rotate('W');
            dice.Rotate('S');
        }
        if(dir == 'W'){
            dice.Rotate('E');
            dice.Rotate('S');
        }
        if(dir == 'B'){
            dice.Rotate('N');
        }
    }

    //Southが一致している状態で呼ぶ
    public static void adaptTop(Dice dice, char dir){
        if(dir == 'W'){
            dice.Rotate('E');
        }
        if(dir == 'B'){
            dice.Rotate('E');
            dice.Rotate('E');
        }
        if(dir == 'E'){
            dice.Rotate('W');
        }
    }

    public Face getFace(char d){
        return faces.First(_ => _.dir == d);
    }

    public static bool SameDice(Dice dice1, Dice dice2){
        var l1 = dice1.faces.Select(_ => _.num).OrderBy(_ => _);
        var l2 = dice2.faces.Select(_ => _.num).OrderBy(_ => _);
        if(l1.SequenceEqual(l2) == false) return false;


        var ss = dice2.faces.Where(_ => _.num == dice1.getFace('S').num);
        if(ss.Count() == 0) return false;

        var d1 = dice1.Copy();
        var d2 = dice2.Copy();

        foreach(var s in ss){
            dice1 = d1.Copy();
            dice2 = d2.Copy();
            Dice.adaptSouth(dice2, s.dir);
            var dice2s = dice2.Copy();

            var ts = dice2.faces.Where(_ => _.num == dice1.getFace('T').num);

            if(ts.Count() == 0) return false;

            foreach(var t in ts){
                if(t.dir == 'N') continue;
                dice2 = dice2s.Copy();
                adaptTop(dice2, t.dir);

                if(Dice.compFacenum(dice1,dice2,'E') && Dice.compFacenum(dice1,dice2,'W') && Dice.compFacenum(dice1,dice2,'N') && Dice.compFacenum(dice1,dice2,'B')){
                    return true;
                }else{
                    continue;
                }
            }
        }
        return false;
    }

    public static bool compFacenum(Dice dice1, Dice dice2, char dir){
        var f1 = dice1.getFace(dir);
        var f2 = dice2.getFace(dir);
        return f1.num == f2.num;
    }
}

class Face{
    public int num;
    public char dir;

    public Face(int n, char d){
        num = n;
        dir = d;
    }
}



Measured memory_bytes: 24664