#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

class Dice {
    private:
        std::vector<int> number;
        std::vector<int> initialize();
        std::string order_list;
        void decide_order(Dice def);
        void decide_slide(Dice def);
        int top;
        int front;
    public: 
        std::string set_order(Dice def);
        std::string set_slide(Dice def);
        void move(std::string orders); 
        void slide(std::string orders); 
        int check(Dice def); 
        Dice() {
            number = initialize();
        }
};

int main(void) {
    int dice_num;
    std::cin >> dice_num;
    Dice def_dice;
    int bool_num = 1;
    for (int i = 0; i < dice_num - 1; i++) {
        Dice dice;
        std::string orders;
        orders = dice.set_order(def_dice);
        dice.move(orders);
        orders = dice.set_slide(def_dice);
        dice.slide(orders);
        bool_num *= dice.check(def_dice);
    }
    if (bool_num == 0) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }
    return EXIT_SUCCESS;
}

std::vector<int> Dice::initialize() {
    number.resize(6);
    int temp;
    for (int surface = 0; surface < 6; surface++) {
        std::cin >> number[surface];
    }
    return number;
}

void Dice::decide_order(Dice def) {
    top = def.number[0];
    std::string move_data[] = {"", "N", "W", "E", "S", "NN"};
    std::vector<std::string> move(move_data, move_data + 6);
    for (int i = 0; i < 6; i++) {
        if (top == number[i]) {
            order_list = move_data[i];                 
            break;
        }
    }
    return;
}

void Dice::decide_slide(Dice def) {
    front = def.number[1];
    std::string move_data[] = {"", "", "L", "R", "RR", ""};
    std::vector<std::string> move(move_data, move_data + 6);
    for (int i = 1; i <= 4; i++) {
        if (front == number[i]) {
            order_list = move_data[i];                 
            break;
        }
    }
}

std::string Dice::set_order(Dice def) {
    decide_order(def);
    return order_list;
}

std::string Dice::set_slide(Dice def) {
    decide_slide(def);
    return order_list;
}

void Dice::move(std::string orders) {
    std::vector<int> new_dice(6 ,0);
    int deflt_data[] = {1, 2, 3, 4, 5, 6};
    std::vector<int> deflt(deflt_data, deflt_data + 6);
    int east_data[] = {4, 2, 1, 6, 5, 3};
    std::vector<int> east(east_data, east_data + 6);
    int west_data[] = {3, 2, 6, 1, 5, 4};
    std::vector<int> west(west_data, west_data + 6);
    int south_data[] = {5, 1, 3, 4, 6, 2};
    std::vector<int> south(south_data, south_data + 6);
    int north_data[] = {2, 6, 3, 4, 1, 5};
    std::vector<int> north(north_data, north_data + 6);

    std::string dir;
    for (int loop = 0; loop < orders.size(); loop++) {
        dir = orders[loop]; 
        if (dir == "E") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[east[loop] - 1];
            }
        } else if (dir == "W") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[west[loop] - 1];
            }
        } else if (dir == "S") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[south[loop] - 1];
            }
        } else if (dir == "N") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[north[loop] - 1];
            }
        }
        number = new_dice;
    }
    return;
}

void Dice::slide(std::string orders) {
    std::vector<int> new_dice(6 ,0);
    int deflt_data[] = {1, 2, 3, 4, 5, 6};
    std::vector<int> deflt(deflt_data, deflt_data + 6);
    int right_data[] = {1, 4, 2, 5, 3, 6};
    std::vector<int> right(right_data, right_data + 6);
    int left_data[] = {1, 3, 5, 2, 4, 6};
    std::vector<int> left(left_data, left_data + 6);

    std::string dir;
    for (int loop = 0; loop < orders.size(); loop++) {
        dir = orders[loop]; 
        if (dir == "R") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[right[loop] - 1];
            }
        } else if (dir == "L") {
            for (int loop = 0; loop < 6; loop++) {
                new_dice[deflt[loop] - 1] = number[left[loop] - 1];
            }
        }
        number = new_dice;
    }
    return;
}

int Dice::check(Dice def) {
    int num;
    bool cod0 = def.number[0] == number[0];
    bool cod1 = def.number[1] == number[1];
    bool cod2 = def.number[2] == number[2];
    bool cod3 = def.number[3] == number[3];
    bool cod4 = def.number[4] == number[4];
    bool cod5 = def.number[5] == number[5];
    if (cod0 && cod1 && cod2 && cod3 && cod4 && cod5) {
        num = 0;
    } else {
        num = 1;
    }
    return num;
}

Measured memory_bytes: 3232