#include <stdio.h>

int main(int argc, const char * argv[]) {
    int s1[102][6];
    int s2[102][6];
    int i,j,tmp,number,count = 0,check=0;
    scanf("%d",&number);
    for(j=0;j<number;j++){
        for(i=0;i<6;i++){
            scanf("%d",&s1[j][i]);
            s2[j][i]=s1[j][i];
        }
    }
        for(j=0;j<number;j++){
            if(check==1){
                break;
            }
            else if(j==number-1){
                printf("Yes\n");
                break;
            }
            while(1){
                if(s1[0][0]==s1[j+1][0]){
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }else if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right spin
                            tmp=s1[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                            
                        }
                    }
        
                }if(s1[0][0]==s2[j+1][1]){
                    tmp=s2[j+1][0];//North
                    s1[j+1][0]=s1[j+1][1];
                    s1[j+1][1]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][4];
                    s1[j+1][4]=tmp;
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right
                            tmp=s2[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                        }
                    }
                }if(s1[0][0]==s1[j+1][2]){
                    tmp=s1[j+1][0];//West
                    s1[j+1][0]=s1[j+1][2];
                    s1[j+1][2]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][3];
                    s1[j+1][3]=tmp;
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right
                            tmp=s2[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                        }
                    }
                }if(s1[0][0]==s1[j+1][3]){
                    tmp=s1[j+1][0];//East
                    s1[j+1][0]=s1[j+1][3];
                    s1[j+1][3]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][2];
                    s1[j+1][2]=tmp;
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right
                            tmp=s1[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                        }
                    }
                    
                }if(s1[0][0]==s1[j+1][4]){
                    tmp=s1[j+1][0];//South
                    s1[j+1][0]=s1[j+1][4];
                    s1[j+1][4]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][1];
                    s1[j+1][1]=tmp;
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right
                            tmp=s1[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                        }
                    }
                    
                }if(s1[0][0]==s1[j+1][5]){
                    tmp=s1[j+1][0];//South
                    s1[j+1][0]=s1[j+1][4];
                    s1[j+1][4]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][1];
                    s1[j+1][1]=tmp;
                    tmp=s1[j+1][0];//South
                    s1[j+1][0]=s1[j+1][4];
                    s1[j+1][4]=s1[j+1][5];
                    s1[j+1][5]=s1[j+1][1];
                    s1[j+1][1]=tmp;
                    while(1){
                        if(s1[0][0]==s1[j+1][0]
                           &&s1[0][1]==s1[j+1][1]
                           &&s1[0][2]==s1[j+1][2]
                           &&s1[0][3]==s1[j+1][3]
                           &&s1[0][4]==s1[j+1][4]
                           &&s1[0][5]==s1[j+1][5]){
                            printf("No\n");
                            check=1;
                            break;
                        }if(count==4){
                            count=0;
                            for(i=0;i<6;i++){
                                s1[j+1][i]=s2[j+1][i];
                            }
                            break;
                        }else{//right
                            tmp=s1[j+1][3];
                            s1[j+1][3]=s1[j+1][4];
                            s1[j+1][4]=s1[j+1][2];
                            s1[j+1][2]=s1[j+1][1];
                            s1[j+1][1]=tmp;
                            count++;
                        }
                    }
                    
                }if(check==1){
                    break;
                }else{
                    break;
                }
            }
        }
    
    return 0;
}




Measured memory_bytes: 2104