#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;
#define rep(i,b,e) for(int i=b; i < e; ++i)
#define Rep(i,n) rep(i,0,n)

class dice
{
    private:
        int roll[6];

    public:
        explicit dice(int in[6]){
            for (int i = 0; i < 6; i++)
                roll[i] = in[i];
        }

        void move(const char c){
            int tmp;
            switch(c){
                case 'N':
                    tmp = roll[0];
                    roll[0] = roll[1];
                    roll[1] = roll[5];
                    roll[5] = roll[4];
                    roll[4] = tmp;
                    break;

                case 'E':
                    tmp = roll[0];
                    roll[0] = roll[3];
                    roll[3] = roll[5];
                    roll[5] = roll[2];
                    roll[2] = tmp;
                    break;

                case 'W':
                    tmp = roll[0];
                    roll[0] = roll[2];
                    roll[2] = roll[5];
                    roll[5] = roll[3];
                    roll[3] = tmp;
                    break;

                case 'S':
                    tmp = roll[0];
                    roll[0] = roll[4];
                    roll[4] = roll[5];
                    roll[5] = roll[1];
                    roll[1] = tmp;
                    break;

                default:
                    cout << "Wrong Direction: "
                         << c << endl;
                    break;
            }
        }
        void roll_R()
        {
            int tmp;
            tmp = roll[1];
            roll[1] = roll[2];
            roll[2] = roll[4];
            roll[4] = roll[3];
            roll[3] = tmp;
        }

        int operator()(size_t i){
            return roll[i];
        }

        void show()
        {
            for (int i = 0; i < 6; i++)
                cout << roll[i] << " " << std::flush;
            cout << endl;
        }

        bool check(dice d)
        {
            for (int i = 0; i < 6; i++)
            {
                if (roll[i]!=d(i))
                    return false;
            }
            return true;
        }

        bool equvalent_to(dice d){
            int count=0;
            while (1)
            {
                count++;
                move('N');
                if (roll[0]==d(0)&&roll[5]==d(5))
                    break;
                move('W');
                if (roll[0]==d(0)&&roll[5]==d(5))
                    break;
                if (count>3) //top,bottomが一致することがなければサイコロ自体一致しない
                    return false;
            }
            //確定でtop,bottomが一致
            
            count = 0;
            while(1)
            {
                count++;
                if (check(d))
                    break;
                roll_R();
                if(count>5)
                    return false;
            }
            return true;  
        }


};

int main(){
    int n, count=1;
    bool judge=false;
    cin >> n;
    std::vector<dice> d;

    Rep(i,n){
        int r[6];
        Rep(j,6) cin >> r[j];
        dice dice(r);
        d.push_back(dice);
    }

    Rep(i,d.size()-1){
        rep(j,i+1,d.size()){
            if(d[i].equvalent_to(d[j])){
                cout << "No" << endl;
                judge=true;
                break;
            }
        }
        if (judge) break;
    }
    if (!judge)
        cout << "Yes" << endl;
    

    return 0;
}


Measured memory_bytes: 3120