#include <stdio.h>
#include <vector>
#include <array>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>

using std::string;
using std::vector;

class Dice {
private:
    // [ ][5][ ]
    // [4][1][3] 
    // [ ][2][ ] 
    int board[3][3];
    int bottom_;
public:
    Dice(vector<int> legends) {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                board[i][j] = -1;
            }
        }
        this->board[0][1] = legends[5-1];
        this->board[1][0] = legends[4-1];
        this->board[1][1] = legends[1-1];
        this->board[1][2] = legends[3-1];
        this->board[2][1] = legends[2-1];
        this->bottom_ = legends[6-1]; 
    }
    void move(char direction) {
        switch (direction) {
            case 'N': {
                int tempBottom = board[0][1];
                board[0][1]    = board[1][1];
                board[1][1]    = board[2][1];
                board[2][1]    = this->bottom_;
                this->bottom_   = tempBottom;
                break;
            }

            case 'E': {
                int tempBottom = board[1][2];
                board[1][2]    = board[1][1];
                board[1][1]    = board[1][0];
                board[1][0]    = this->bottom_;
                this->bottom_   = tempBottom;
                break;
            }
            case 'W': {
                int tempBottom = board[1][0];
                board[1][0]    = board[1][1];
                board[1][1]    = board[1][2];
                board[1][2]    = this->bottom_;
                this->bottom_   = tempBottom;
                break;
            }
            case 'S': {
                int tempBottom = board[2][1];
                board[2][1]    = board[1][1];
                board[1][1]    = board[0][1];
                board[0][1]    = this->bottom_;
                this->bottom_   = tempBottom;
                break;
            }
        }
    }
    void printBoard() {
        printf("------------\n");
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++){
                printf("[% d] ", this->board[i][j]);
            }
            printf("\n");
        }
    }    
    int top() {
        return this->board[1][1];
    }
    int front() {
        return this->board[2][1];
    }
    void front(int n){
        this->board[2][1] = n;
    }
    int left() {
        return this->board[1][0];
    }
    void left(int n){
        this->board[1][0] = n;
    }
    int right() {
        return this->board[1][2];
    }
    void right(int n) {
        this->board[1][2] = n;
    }
    int back() {
        return this->board[0][1];
    }
    void back(int n) {
        this->board[0][1] = n;
    }
    int bottom() {
        return this->bottom_;
    }
    void clockwise() {
        int temp = this->back();
        this->back(this->left());
        this->left(this->front());
        this->front(this->right());
        this->right(temp);
        // printBoard();
    }
    int getRight(int front) {
        for (int i = 0; i < 4; i++){
            this->clockwise();
            if (this->front() == front) return this->right();
        }
        return -2;
    }

    int searchRight(int top, int front) {
        for (int i = 0; i < 6; i++) {
            const char direction = i % 2 == 0 ? 'S' : 'W';
            this->move(direction);
            if (top == this->top()) {
                return this->getRight(front);
            } 
        }
        return -1;
    }
};
int main(){
    vector<Dice> dices = {};
    int n = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int n1, n2, n3, n4, n5, n6;
        scanf("%d %d %d %d %d %d", &n1, &n2, &n3, &n4, &n5, &n6);
        dices.push_back(Dice({ n1, n2, n3, n4, n5, n6 }));
    }

    bool matched = false;
    // all dices
    for (int i = 0; i < dices.size(); i++) {
        for (int ii = i + 1; ii < dices.size(); ii++ ) {
            auto lhs = dices[i];
            auto rhs = dices[ii];

            // 6面 search
            for(int j = 0; j < 6; j++) {
                const char direction = j % 2 == 0 ? 'S' : 'W';
                rhs.move(direction);
                // 4方向
                if (lhs.top() == rhs.top()) {
                    for (int k = 0; k < 4; k++){
                        rhs.clockwise();
                        if (lhs.front()  != rhs.front()) continue;
                        if (lhs.back()   != rhs.back()) continue;
                        if (lhs.right()  != rhs.right()) continue;
                        if (lhs.left()   != rhs.left()) continue;
                        if (lhs.bottom() != rhs.bottom()) continue;
                        // match
                        printf("No\n");
                        return 0;
                    }
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3180