#include <iostream>
#include <vector>

using namespace std;

vector<int> memo;

class Dice{
    int s[6];   //?????????????????¢
public:
    Dice(){};
    Dice(int *);
    void throw_dice(char);
    int get_up() const {return s[0];}
    int get_s(int n) const {return s[n];}
    int get_hash() const;
    void set_s(int *);
};

Dice::Dice(int *dice_s){
    for (int i=0;i<6;i++) s[i]=dice_s[i];
}

void Dice::set_s(int *dice_s){
    for (int i=0;i<6;i++) s[i]=dice_s[i];
}

void Dice::throw_dice(char d){
    int temp,temp2;
    switch(d){
        case 'S':
            temp=temp2=s[2-1];
            s[2-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[5-1];
            s[5-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'E':
            temp=temp2=s[3-1];
            s[3-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[4-1];
            s[4-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'N':
            temp=temp2=s[5-1];
            s[5-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[2-1];
            s[2-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        case 'W':
            temp=temp2=s[4-1];
            s[4-1]=s[1-1];
            temp2=s[6-1];
            s[6-1]=temp;
            temp=temp2;
            temp2=s[3-1];
            s[3-1]=temp;
            temp=temp2;
            s[1-1]=temp;
            break;
        default:
            cout<<"Error!";
            break;
    }
}

int Dice::get_hash() const{
    return s[0]+10*s[1]+100*s[2]+1000*s[3]+10000*s[4]+100000*s[5];
}

bool operator == (const Dice &d1,const Dice &d2){
    for (int i=0;i<6;i++){
        if (d1.get_s(i)!=d2.get_s(i)){
            return false;
        }
    }
    return true;
}

int comp_dice(const Dice &d1,Dice d2);

int main(){
    int s[6];
    int i,j;
    int n;
    cin>>n;
    Dice *d;
    d=new Dice [n];
    if (d==NULL){
        cout<<"Error!"<<endl;
        return 0;
    }
    for (i=0;i<n;i++){
        for (j=0;j<6;j++){
            cin>>s[j];
        }
        d[i].set_s(s);
    }
    int flg=0;
    for (i=0;i<n;i++){
        for (j=i+1;j<n;j++){
        memo.clear();
        if (comp_dice(d[i],d[j]))
            //??????????????????????????£???
            flg=1;
        }
    }
    if (flg){
        //??????????????????????????£???
        cout<<"No"<<endl;
    }
    else{
        //???????????????????????£???
        cout<<"Yes"<<endl;
    }
    delete [] d;
    return 0;
}

int comp_dice(const Dice &d1,Dice d2){
    int hash=d2.get_hash();
    for (vector<int>::iterator i=memo.begin();i!=memo.end();i++){
        if (hash==*i){
            //?????§????§£?????????????????????
            return 0;
        }
    }
    memo.push_back(hash);
    if (d1==d2){
        return 1;
    }
    Dice tempd1(d2);
    Dice tempd2(d2);
    Dice tempd3(d2);
    Dice tempd4(d2);
    tempd1.throw_dice('S');
    tempd2.throw_dice('E');
    tempd3.throw_dice('N');
    tempd4.throw_dice('W');
    return comp_dice(d1,tempd1)+comp_dice(d1,tempd2)+comp_dice(d1,tempd3)+comp_dice(d1,tempd4);
}

Measured memory_bytes: 1220