#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;

struct saikoro{

    int Size[6] = {0};
    int up, down;
    int south, east, west, north;
    int next_up, next_down, next_south, next_east, next_west, next_north;
public : 
    saikoro(){  //初期化
        up = Size[0];
        south = Size[1];
        east = Size[2];
        west = Size[3];
        north = Size[4];
        down = Size[5];

        next_up = 0;
        next_south = 0;
        next_north = 0;
        next_east = 0;
        next_west = 0;
        next_down = 0;
    }

    void init(){  //再初期化
        up = Size[0];
        south = Size[1];
        east = Size[2];
        west = Size[3];
        north = Size[4];
        down = Size[5];
    }
    void change(char ch){
        if(ch == 'S'){
        next_up = north;
        next_south = up;
        next_north = down;
        next_down = south;

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'N'){
        next_up = south;
        next_south = down;
        next_north = up;
        next_down = north; 

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'E'){
        next_up = west;
        next_east = up;
        next_west = down;
        next_down = east; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        } else if(ch == 'W'){       
        next_up = east;
        next_east = down;
        next_west = up;
        next_down = west; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        }else if(ch == 'R'){
        next_south = west;
        next_east = south;
        next_west = north;
        next_north = east; 

        south = next_south;
        east = next_east;
        west = next_west;
        north = next_north;
        }
    }
};

int main(){

    int n;
    scanf("%d", &n);
    saikoro A[n];

    //初期化
    for(int i=0; i<n; i++){
        for(int j=0; j<6; j++){
        scanf("%d", &A[i].Size[j]);
     }
    A[i].init();
    }

    //全探索
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){

        for(int k=0; k<6; k++){
        
        //頂点合わせる
        if(k==1) A[i].change('N');
        if(k==2) A[i].change('W');
        if(k==3) A[i].change('E');
        if(k==4) A[i].change('S');
        if(k==5) {
            A[i].change('N');
            A[i].change('N');
            }

        for(int l=0; l<6; l++){

        if(A[i].up == A[j].Size[l]){
            //upを合わせる
            if(A[j].Size[l] == A[j].north) A[j].change('S');
            else if(A[j].Size[l] == A[j].south) A[j].change('N');
            else if(A[j].Size[l] == A[j].west) A[j].change('E');
            else if(A[j].Size[l] == A[j].east) A[j].change('W');
            else if(A[j].Size[l] == A[j].down) {
                A[j].change('N');
                A[j].change('N');
            }
    if(A[i].south != A[j].south) A[j].change('R');
    if(A[i].south != A[j].south) A[j].change('R');
    if(A[i].south != A[j].south) A[j].change('R');
    if((A[i].north==A[j].north)&&(A[i].south==A[j].south)&&(A[i].west==A[j].west)&&(A[i].east==A[j].east)&&(A[i].down==A[j].down)){
        printf("No\n");
        return 0;
                }      
            }
        }
    }

        }
    }

    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2704