#include <stdio.h>
#include <string.h>

typedef struct{
    int arr[6];
    //***軸は半時計周り***
    int X[4];//top front btm back
    int Y[4];//front right back left
    int Z[4];//top left btm right
}Dice;

void init_dice(Dice *d){
    //top
    d->X[0] = d->arr[0];
    d->Z[0] = d->arr[0];
    //front
    d->X[1] = d->arr[1];
    d->Y[0] = d->arr[1];
    //right
    d->Y[1] = d->arr[2];
    d->Z[3] = d->arr[2];
    //left
    d->Y[3] = d->arr[3];
    d->Z[1] = d->arr[3];
    //back
    d->X[3] = d->arr[4];
    d->Y[2] = d->arr[4];
    //bottom
    d->X[2] = d->arr[5];
    d->Z[2] = d->arr[5];
}

int rotate_X(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //North : n=1
    //South : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = X[j + 1];
            X[j + 1] = X[j];
            X[j] = tmp;
        }
    }
    Z[0] = X[0];
    Y[0] = X[1];
    Z[2] = X[2];
    Y[2] = X[3];
}

int rotate_Y(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //Left : n=1
    //Right : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = Y[j + 1];
            Y[j + 1] = Y[j];
            Y[j] = tmp;
        }
    }
    X[1] = Y[0];
    Z[3] = Y[1];
    X[3] = Y[2];
    Z[1] = Y[3];
}

int rotate_Z(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //East : n=1
    //West : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = Z[j + 1];
            Z[j + 1] = Z[j];
            Z[j] = tmp;
        }
    }

    //sync
    X[0] = Z[0]; //top
    Y[3] = Z[1]; //left
    X[2] = Z[2]; //btm
    Y[1] = Z[3]; //right
}

int find_top(Dice *d, int ptn){
    int i;
    if(d->X[0] == ptn)return 0;
    for(i = 0; i < 3; i++){
        rotate_X(d->X, d->Y, d->Z, 1);
        if(d->X[0] == ptn){
            return 0;
        }
    }
    for(i = 0; i < 3; i++){
        rotate_Z(d->X, d->Y, d->Z, 1);
        if(d->X[0] == ptn){
            return 0;
        }
    }
    return -1;
}

int find_front(Dice *d, int ptn){
    int i;
    if(d->Y[0] == ptn)return 0;
    for(i = 0; i < 3; i++){
        rotate_Y(d->X, d->Y, d->Z, 1);
        if(d->Y[0] == ptn){
            return 0;
        }
    }
    return -1;
}

int compare_dice(Dice *d1, Dice *d2){
    int i, j;
    for(i = 0; i < 6; i++){
        init_dice(d1);
        init_dice(d2);

        find_top(d1, d1->arr[i]);

        if(find_top(d2, d1->arr[i]) == -1)return -1;
        if(find_front(d2, d1->Y[0]) == -1)return -1;

        for(j = 0; j < 4; j++){
            if(d1->X[j] != d2->X[j])break;
        }
        if(j < 4)continue;

        for(j = 0; j < 4; j++){
            if(d1->Y[j] != d2->Y[j])break;
        }
        if(j == 4)return i;
    }
    return -1;
}


int main(){
    Dice dice[100];
    int i, j, n;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        for(j = 0; j < 6; j++){
            getchar();
            scanf("%d", &dice[i].arr[j]);
        }
        init_dice(&dice[i]);
    }

    int flag = 0;
    for(i = 0; i < n - 1; i++){
        for(j = i + 1; j < n; j++){
            if(compare_dice(&dice[i], &dice[j]) >= 0){
                flag = i + j;
                break;
            }
        } 
        if(flag)break;
    }

    if(!flag)printf("Yes\n");
    else printf("No\n");
}



Measured memory_bytes: 2120