#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <array>

using namespace std;

class Dice {
    int num_up;
    int num_s;
    int num_w;
    int num_n;
    int num_e;
    int num_bot;
    
public:
    //???????????????????????????
    Dice()
    {
        num_up = num_s = num_w = num_n = num_e = num_bot = 0;
    }
    
    Dice(int num1, int num2, int num3, int num4, int num5, int num6)
    : num_up( num1 )
    , num_s( num2 )
    , num_e( num3 )
    , num_w( num4 )
    , num_n( num5)
    , num_bot( num6 )
    {
    }
    
    Dice(string str)
    {
        stringstream ss(str);
        ss >> num_up >> num_s >> num_e >> num_w >> num_n >> num_bot;
    }
    
    //static??¢??°??????
    static bool isSameDice(Dice x, Dice y) {
        int cntVerticalSpin = 0;
        int cntHorizontalSpin = 0;
        
//        //for debug
//        cout << "y\n";
//        y.printDevelopment();
//        cout << "x\n";
//        x.printDevelopment();
        
        
        //x,y????????¢????????´???????????§x?????¨???????????¢?????????
        for( cntVerticalSpin=0; cntVerticalSpin<4; cntVerticalSpin++) {
            
            for( cntHorizontalSpin=0; cntHorizontalSpin<4; cntHorizontalSpin++ ) { //cnt=0,1,2,3??§?¨?4?????¢??????1??¨??????
                if( x.num_up == y.num_up && x.num_s == y.num_s && x.num_e == y.num_e && x.num_w == y.num_w && x.num_n == y.num_n && x.num_bot == y.num_bot ) {
                    
//                    //for debug
//                    x.printDevelopment();
                    
                    return true;
                } else {
                    x.spinRight();
                    
//                    //for debug
//                    cout << "\n?¨????" << cntHorizontalSpin << "?????¢??????" << endl;
//                    x.printDevelopment();

                }
            }
            
            x.rollToN(); //cnt=0,1,2,3??§???4?????¢??????1??¨??????
            
//            //for debug
//            cout << "\n??????" << cntVerticalSpin << "?????¢?????? -----------------------------------" << endl;
//            x.printDevelopment();
            
        } //???????????§??§up,front,back,bot????????¢???????????¨????????¢?´¢??????????????????left,right????????¢???????????±??????
        
        //right????????¢????????£?????????
        x.spinRight();
        x.rollToN();
        
//        //for debug
//        cout << "\nright????????¢????????£???????????? =============================================" << endl;
//        x.printDevelopment();
        
        
        
        for( cntVerticalSpin=0; cntVerticalSpin<2; cntVerticalSpin++) { //left,right????????¢?????????2??±????????????????????°??????
            
            for( cntHorizontalSpin=0; cntHorizontalSpin<4; cntHorizontalSpin++ ) { //cnt=0,1,2,3??§?¨?4?????¢??????1??¨??????
                if( x.num_up == y.num_up && x.num_s == y.num_s && x.num_e == y.num_e && x.num_w == y.num_w && x.num_n == y.num_n && x.num_bot == y.num_bot ) {

//                    //for debug
//                    cout << "?????´????????????\n";
//                    cout << "x\n";
//                    x.printDevelopment();
//                    cout << "y\n";
//                    y.printDevelopment();
                    
                    return true;
                } else {
                    x.spinRight();
                    
//                    //for debug
//                    cout << "\n?¨????" << cntHorizontalSpin << "?????¢??????" << endl;
//                    x.printDevelopment();
                }
            }
            
            //2?????¢??????left????????¢?????£????????????right????????¢????????£?????????
            x.rollToN();
            x.rollToN();
            
//            //for debug
//            cout << "\n??????" << cntVerticalSpin << "?????¢?????? -----------------------------------" << endl;
//            x.printDevelopment();
            
        } //????????§??¨????????????
        
        //??¨???????????¢?????????????????´???????????£????????§x??¨y?????°??????
        return false;
    }
    
    //??\??????????????¢??°??????
    int getUpperNumber(void) {
        return num_up;
    }
    
    int getFrontNumber(void) {
        return num_s;
    }
    
    int getRightNumber(void) {
        return num_e;
    }
    
    void printAllNumber(void) {
            cout << num_up << " " << num_s << " " << num_e << " " << num_w << " " << num_n << " " << num_bot << endl;
    }
    
    void printDevelopment(void) {
        cout << "     ---\n";
        cout << "    |" << setw(3) << num_up << "|       " << "\n";
        cout << " --- --- --- ---\n";
        cout << "|" << setw(3) << num_w << "|" << setw(3) << num_s << "|" << setw(3) << num_e << "|" << setw(3) << num_n << "|\n";
        cout << " --- --- --- ---\n";
        cout << "    |" << setw(3) << num_bot << "|\n";
        cout << "     ---\n";
        //     ---
        //    |100|
        // --- --- --- ---
        //|xx3|  x|xxx|xxx|
        // --- --- --- ---
        //    |xxx|
        //     ---
    }
    
    void rollToN() {
        int tmp;
        tmp = num_bot;
        num_bot = num_n;
        num_n = num_up;
        num_up = num_s;
        num_s = tmp;
    }
    
    void rollToS() {
        int tmp;
        tmp = num_bot;
        num_bot = num_s;
        num_s = num_up;
        num_up = num_n;
        num_n = tmp;
    }
    
    void rollToE() {
        int tmp;
        tmp = num_bot;
        num_bot = num_e;
        num_e = num_up;
        num_up = num_w;
        num_w = tmp;
    }
    
    void rollToW() {
        int tmp;
        tmp = num_bot;
        num_bot = num_w;
        num_w = num_up;
        num_up = num_e;
        num_e = tmp;
    }
    
    void spinRight() {
        int tmp;
        tmp = num_s;
        num_s = num_e;
        num_e = num_n;
        num_n = num_w;
        num_w = tmp;
    }
    
    void rollCommandWithChar(char c) {
        switch (c) {
            case 'E':
                rollToE();
                break;
                
            case 'N':
                rollToN();
                break;
                
            case 'S':
                rollToS();
                break;
                
            case 'W':
                rollToW();
                break;
                
            default:
                break;
        }
    }
    
    bool rollUntilThisUpperFront(int upper, int front) {
        int cnt;
        
        //?????¢??????????????°??????????????§??¨??????????????¢?????????
        cnt = 0;
        while(getUpperNumber() != upper) {
            if(cnt<3) { //cnt=0,1,2??§3?????¢
                rollToN();
                cnt++;
            } else if(cnt==3) {
                spinRight();
                cnt++;
            } else if(cnt<7) { //4,5,6??§3?????¢
                rollToN();
                cnt++;
            } else {
//                cout << "ERROR!! : UPPER is Not Found" << endl;
                return false;
            }
        }
        
//        //test display
//        printDevelopment();
        
        
        //?????¢??????????????°??????????????§??´??¢???????????¢
        cnt = 0;
        while(getFrontNumber() != front) {
            if(cnt<3) { //cnt=0,1,2??§3?????¢
                spinRight();
                cnt++;
            } else {
//                cout << "ERROR!! : FRONT is Not Found" << endl;
                return false;
            }
        }
        
//        //test display
//        printDevelopment();
        
        return true;
    }
};


int main(void) {
    string str;
    int N;
    
    getline(cin, str);
    stringstream ss(str);
    ss >> N;
    
    vector<Dice> dices;

    for(int i=0; i<N; i++) {
        getline(cin, str);
        
//        //for debug
//        cout << i << " : " << str << endl;

        Dice x(str);
        
        dices.push_back( x );
    }
    
    
//    //for debug
//    cout << "dices.size() = " << dices.size() << endl;
//    for(auto i : dices) {
//        i.printDevelopment();
//    }

    
    bool isAllDifferentDice = true;
    for(int i=0; i<N-1; i++) {
        for(int j=i+1; j<N; j++) {
            isAllDifferentDice = isAllDifferentDice && !Dice::isSameDice(dices[i], dices[j]); //1?????§???????????????????????£?????????false?????????
            
//            //for debug
//            if( Dice::isSameDice(dices[i], dices[j]) ) {
//                cout << "i = " << i << " == j = " << j << endl;
//            }
        }
    }

    if( isAllDifferentDice == true )
        cout << "Yes\n";
    else
        cout << "No\n";
    
    return 0;
    
}

Measured memory_bytes: 3160