// https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/11/ITP1_11_C
/*
      1        N
    4 2 3 5  W   E
      6        S

    upper:1 lower:6 front:2 back:5 left:4 right:3
    
    upper->front->right->left->back->lower

    N: 1->5 2->1 6->2 5->6
    S: 1->2 2->6 6->5 5->1  
    E: 1->3 3->6 6->4 4->1
    W: 1->4 4->6 6->3 3->1 

    right 1: /2 3/3 5/5 4/4 2/
    right 2: /1 4/4 6/6 3/3 1/
    right 3: /1 2/2 6/6 5/5 1/
    right 4: /1 5/5 6/6 2/2 1/
    right 5: /1 3/3 6/6 4/4 1/
    right 6: /2 4/4 5/5 3/3 2/
*/

#include <iostream>
#include <cstring>
#include <vector>

using std::vector;

class dice
{

public:
    dice();
    void SetPips();
    int GetUpperPip() { return pip[0]; };
    int GetArbRightPip(const vector<vector<vector<int>>> &V, int upper, int front);
    void RollDice(char order);
    void PrintDice();
    bool operator==(const dice &d2) const { return !memcmp(pip, d2.pip, sizeof(int) * 6); };
    bool operator!=(const dice &d2) const { return memcmp(pip, d2.pip, sizeof(int) * 6); };
    friend std::ostream &operator<<(std::ostream &out, const dice &d);

private:
    int pip[6];
};

int main()
{
    vector<vector<vector<int>>> V =
        {{{1, 2}, {2, 4}, {4, 3}, {3, 1}},
         {{0, 3}, {3, 5}, {5, 2}, {2, 0}},
         {{0, 1}, {1, 5}, {5, 4}, {4, 0}},
         {{0, 4}, {4, 5}, {5, 1}, {1, 0}},
         {{0, 2}, {2, 5}, {5, 3}, {3, 0}},
         {{1, 3}, {3, 4}, {4, 2}, {2, 1}}};

    int n;
    std::cin >> n;

    dice d[n];
    dice d1, d2;

    for (int i = 0; i < n; i++)
        d[i].SetPips();

    for (int ii = 0; ii < n; ii++)
    {
        for (int jj = 0; jj < n; jj++)
        {
            if (ii < jj)
            {
                d1 = d[ii];
                d2 = d[jj];
                for (int i = 0; i < 4; i++)
                {
                    d2.RollDice('W');
                    for (int j = 0; j < 4; j++)
                    {
                        d2.RollDice('S');
                        for (int k = 0; k < 4; k++)
                        {
                            d2.RollDice('W');
                            if (d1 == d2)
                            {
                                std::cout << "No" << std::endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }

    std::cout << "Yes" << std::endl;
    return 0;
}

dice::dice() : pip{}
{
}

void dice::SetPips()
{
    for (int i = 0; i < 6; i++)
        std::cin >> pip[i];
}

int dice::GetArbRightPip(const vector<vector<vector<int>>> &V, int upper, int front)
{
    int match;

    bool tmp[2] = {0, 0};
    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            tmp[0] = tmp[1] = 0;
            for (int k = 0; k < 2; k++)
            {
                if (k == 0 && pip[V.at(i).at(j).at(k)] == upper)
                    tmp[k] = true;
                else if (k == 1 && pip[V.at(i).at(j).at(k)] == front)
                    tmp[k] = true;

                if (tmp[0] == true && tmp[1] == true)
                {
                    match = i;
                    return pip[match];
                }
            }
        }
    }
    return -1;
}

void dice::RollDice(char order)
{
    int buff;
    switch (order)
    {
    case 'N':
    {
        buff = pip[0];
        pip[0] = pip[1];
        pip[1] = pip[5];
        pip[5] = pip[4];
        pip[4] = buff;
        break;
    }
    case 'S':
    {
        buff = pip[0];
        pip[0] = pip[4];
        pip[4] = pip[5];
        pip[5] = pip[1];
        pip[1] = buff;
        break;
    }
    case 'E':
    {
        buff = pip[0];
        pip[0] = pip[3];
        pip[3] = pip[5];
        pip[5] = pip[2];
        pip[2] = buff;
        break;
    }
    case 'W':
    {
        buff = pip[0];
        pip[0] = pip[2];
        pip[2] = pip[5];
        pip[5] = pip[3];
        pip[3] = buff;
        break;
    }
    }
}

void dice::PrintDice()
{
    for (auto x : pip)
    {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

std::ostream &operator<<(std::ostream &out, const dice &d)
{
    for (auto &x : d.pip)
    {
        out << x << " ";
    }
}


Measured memory_bytes: 3176