#include<iostream>
using namespace std;

class Dice{
public:
    int face[7];

    int center;
    int top;
    int bottom;
    int left;
    int right;
    int back;

    Dice(int num[]){
        for(int i = 1; i <= 6; i++){
            face[i] = num[i];
        }
        init();
    }

    void init(){
        center = 1;
        top = 5;
        bottom = 2;
        left = 4;
        right = 3;
        back = 6;
    }
 
    void move(char command){
        int tmp;
        switch(command){
            case 'E':
                top = top; // 変化せず
                bottom = bottom; // 変化せず
                tmp = right;
                right = center;
                center = left;
                left = back;
                back = tmp;
                // printDebug();
                break;
            case 'N':
                left = left; // 変化せず
                right = right; // 変化せず
                tmp = top;
                top = center;
                center = bottom;
                bottom = back;
                back = tmp;
                // printDebug();
                break;
            case 'S':
                left = left; // 変化せず
                right = right; // 変化せず
                tmp = bottom;
                bottom = center;
                center = top;
                top = back;
                back = tmp;
                // printDebug();
                break;
            case 'W':
                top = top; // 変化せず
                bottom = bottom; // 変化せず
                tmp = left;
                left = center;
                center = right;
                right = back;
                back = tmp;
                // printDebug();
                break;
        }
    }

    void rotateRight(){
        int tmp = top;
        top = right;
        right = bottom;
        bottom = left;
        left = tmp;
    }

    void setCenter(int _no){
        switch(_no){
            case 1:
                // 何もしない
                break;
            case 2:
                move('N');
                break;
            case 3:
                move('W');
                break;
            case 4:
                move('E');
                break;
            case 5:
                move('S');
                break;
            case 6:
                move('S');
                move('S');
                break;
        }
    }
    void setBottom(int _bottom){
        int diceIndex = 0;
        for(int i = 1; i <= 6; i++){
            if(_bottom == face[i]){
                diceIndex = i;
                break;
            }
        }
        while(bottom != diceIndex){
            rotateRight();
        }
    }

    void printFaces(){
        cout << face[center] << face[bottom] << face[right] << face[left] << face[top] << face[back] << endl;
    }

    void printStatus(){
        cout << center << bottom << right << left << top << back << endl;
    }

};

bool isSameDices(Dice diceA, Dice diceB){
    if(diceA.face[diceA.center] != diceB.face[diceB.center]){
        return false;
    }
    if(diceA.face[diceA.top] != diceB.face[diceB.top]){
        return false;
    }
    if(diceA.face[diceA.bottom] != diceB.face[diceB.bottom]){
        return false;
    }
    if(diceA.face[diceA.right] != diceB.face[diceB.right]){
        return false;
    }
    if(diceA.face[diceA.left] != diceB.face[diceB.left]){
        return false;
    }
    if(diceA.face[diceA.back] != diceB.face[diceB.back]){
        return false;
    }

    return true;
}

int main(){
    int num;
    int face;
    int arrayA[7];
    int arrayB[7];

    cin >> num;

    for(int i = 1; i <= 6; i++){
        // cin >> num;
        cin >> face;
        // arrayA[i] = num;
        arrayA[i] = face;
    }
    Dice dice1(arrayA);
    // dice1.printStatus();
    // dice1.printFaces();

    // cout << num << endl;
    for(int i = 0; i < (num - 1); i++){
        for(int i = 1; i <= 6; i++){
            cin >> face;
            // arrayB[i] = num;
            arrayB[i] = face;
        }
        Dice dice2(arrayB);
        // dice2.printStatus();
        // dice2.printFaces();
        for(int i = 1; i <= 6; i++){
            dice2.setCenter(i);
            for(int j = 1; j <= 4; j++){
                dice2.rotateRight();

                // 入力されたサイコロがすべて異なる場合 "Yes"、
                // 同じものが１組以上含まれる場合 "No" と１行に出力してください。
                if(isSameDices(dice1, dice2)){
                    // cout << "Yes" << endl;
                    cout << "No" << endl;
                    return 0;
                } else {
                    // cout << "No" << endl;
                    // cout << "Yes" << endl;
                }
            }
            dice2.init();
        }
    }

    cout << "Yes" << endl;




    // cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3092