/*
   AOJ - ITP11_1_d
Date: 20181025
Author: Mikoron * ♡mikoiwate351♡
*/

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

#define DMAX 101
#define TOP 1
#define FRONT 2
#define RIGHT 3
#define LEFT 4
#define BACK 5
#define BOTTOM 6


typedef struct {
        short suf[7];
} dice_state_t;

void show_surface(dice_state_t *dice, short s_suf);
void rot_dice(dice_state_t *dice, char command);
short search_tow_side(dice_state_t *dice, short s_TOP, short s_FRONT);
short compare_dice(dice_state_t *dice1, dice_state_t *dice2);
void rot_y(dice_state_t *dice);
void rot_x(dice_state_t *dice);
void rot_z(dice_state_t *dice);

int main(void) {

        short i, j, dice_num;

        dice_state_t dice[DMAX];

        scanf("%hd", &dice_num);

        for(i = 0; i < dice_num; i++) {
                for(j = 1; j < 7; j++) scanf("%hd", &dice[i].suf[j]);
        }

        for(i = 0; i < dice_num - 1; i++) {
                for(j = i + 1; j < dice_num; j++) {
                        if(!compare_dice(&dice[i], &dice[j])) {
                                printf("No\n");
                                return 0;
                        }
                }

        }
        printf("Yes\n");

        return 0;
}

void show_surface(dice_state_t *dice, short s_suf) {
        printf("%hd\n", dice->suf[s_suf]);
}


void rot_dice(dice_state_t *dice, char command) {
        short i;

        switch(command) {
                case 'N':
                        rot_y(dice);
                        break;
                case 'E':
                        rot_x(dice);
                        break;
                case 'S':
                        for(i = 0; i < 3; i++) rot_y(dice);
                        break;
                case 'W':
                        for(i = 0; i < 3; i++) rot_x(dice);
                        break;
        }

}

short search_tow_side(dice_state_t *dice, short s_TOP, short s_FRONT) {
        short flag_TOP = 0, flag_FRONT = 0, i, j;
        for(i = 0; i < 2; i++) {
                if(flag_TOP == 1) break;
                for(j = 0; j < 4; j++) {
                        if(dice->suf[TOP] == s_TOP) flag_TOP = 1;
                        if(flag_TOP == 1) break;
                        if(i == 0) rot_y(dice);
                        else if(i == 1) rot_x(dice);
                }
        }

        for(i = 0; i < 3; i++) {
                if(dice->suf[FRONT] == s_FRONT) {
                        flag_FRONT = 1;
                        break;
                }
                rot_z(dice);
        }
        if(flag_TOP == 1 && flag_FRONT == 1) return 0;
        else return 1;
}

short compare_dice(dice_state_t *dice1, dice_state_t *dice2) {
        short i, j, k, l, flag;
        for(i = 0; i < 2; i++) {
                for(j = 0; j < 4; j++) {
                        for(k = 0; k < 4; k++) {
                                flag = 1;
                                for(l = 1; l < 7; l++) {
                                        if(dice2->suf[l] != dice1->suf[l]) {
                                                flag = 0;
                                                break;
                                        }
                                }
                                if(flag == 1) return 0;
                                rot_z(dice2);
                        }
                        if(i == 0) rot_y(dice2);
                        else if(i == 1) rot_x(dice2);
                }
        }
        return 1;

}


void rot_y(dice_state_t *dice) {
        short buf;

        buf = dice->suf[TOP];
        dice->suf[TOP] = dice->suf[FRONT]; // 1 -> 2
        dice->suf[FRONT] = dice->suf[BOTTOM]; // 2 -> 6
        dice->suf[BOTTOM] = dice->suf[BACK]; // 6 -> 5
        dice->suf[BACK] = buf; // 5 -> 1
}


void rot_x(dice_state_t *dice) {
        short buf;

        buf = dice->suf[TOP];
        dice->suf[TOP] = dice->suf[LEFT]; // 1 -> 4
        dice->suf[LEFT] = dice->suf[BOTTOM]; // 4 -> 6
        dice->suf[BOTTOM] = dice->suf[RIGHT]; // 6 -> 3
        dice->suf[RIGHT] = buf; // 3 -> 1
}

void rot_z(dice_state_t *dice) {
        short buf;

        buf = dice->suf[FRONT];
        dice->suf[FRONT] = dice->suf[RIGHT]; // 2 -> 3
        dice->suf[RIGHT] = dice->suf[BACK]; // 3 -> 5
        dice->suf[BACK] = dice->suf[LEFT]; // 5 -> 4
        dice->suf[LEFT] = buf; // 4 -> 2
}



Measured memory_bytes: 2136