#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
int main() {
    int n;
    cin >> n;
    int x[n][6];
    for (int i=0;i<n;i++){
        for (int j=0; j<6; j++) {
            cin >> x[i][j];
        }
    }
    
    char a[30]= {'N','N','N','N','E','E','E','N','N','N','E','E','E','N','N','N','E','N','N','N','E','N','N','N','E','E','E','N','N','N'};
    int b,c,d,e;
    b=c=d=e=0;
    for(int k=0;k<n;k++){
        for (int i=0;i<30;i++){
            if (a[i]=='E') {
                b=x[k][0];c=x[k][2];d=x[k][3];e=x[k][5];
                x[k][2]=b;x[k][5]=c;x[k][0]=d;x[k][3]=e;
                }
            
            if(a[i]=='N'){
                b=x[k][0];c=x[k][1];d=x[k][4];e=x[k][5];
                x[k][4]=b;x[k][0]=c;x[k][5]=d;x[k][1]=e;
                }
        for(int j=0;j<k;j++){
            if(x[j][0]==x[k][0]&&x[j][1]==x[k][1]&&x[j][2]==x[k][2]&&x[j][3]==x[k][3]&&x[j][4]==x[k][4]&&x[j][5]==x[k][5]){
                cout << "No"<<endl;
                goto l;
            }
        }
            }
        if(k == n-1){
            cout << "Yes" << endl;
            goto l;
        }
        }
    l:;
    return 0;
    
    }


