#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

class m_int{
    public:
    int_fast32_t MOD = max_int;
    int_fast32_t d=0;
    m_int operator =(int x){
        this->d = (int_fast32_t)x;
        return *this;
    }
    m_int operator =(const m_int x){
        this->d = x.d;
        return *this;
    }
    m_int operator+(const m_int &another) const{
        m_int tmp;
        if(d+another.d>MOD){
            tmp.d = d+another.d-MOD;
            return tmp;
        }
        else{
            tmp.d = d+another.d;
            return tmp;
        }
    }
    m_int operator+=(const m_int another){
        (*this) = (*this) + another;
        return *this;
    }
    m_int operator-(const m_int &another) const{
        m_int tmp;
        if(d-another.d<(int_fast32_t)0){
            tmp.d = d-another.d+MOD;
            return tmp;
        }
        else{
            tmp.d = d-another.d;
            return tmp;
        }
    }
    m_int operator*(const m_int &another) const{
        m_int tmp;
        tmp.d = d*another.d%MOD;
        return tmp;
    }
    m_int operator*(int x){
        m_int tmp;
        tmp.d = d*x%MOD;
        return tmp;
    }
    /*
    m_int operator/(const m_int &another) const{
        m_int tmp;
        if(d-another.d<(int_fast32_t)0){
            tmp.d = d-another.d+MOD;
            return tmp;
        }
        else{
            tmp.d = d-another.d;
            return tmp;
        }
    }*/
    bool operator<(const m_int &another) const{
        return d < another.d;
    }
    bool operator>(const m_int &another) const{
        return d > another.d;
    }
};
ostream& operator<<(std::ostream& os, const m_int& obj){
    // ここでストリームに obj を書き込みます。
    os << obj.d;
    return os;
}
istream& operator>>(std::istream& is, m_int& obj){
    // ここでストリームから obj を読み込みます。
    is >> obj.d;
    if( false ) is.setstate(std::ios::failbit);
    return is;
}

class Dice{
    public:
    int up,down,left,right,front,back;
    Dice(int up,int front,int right,int left,int back,int down){
        this->up = up;
        this->down = down;
        this->left = left;
        this->right = right;
        this->front = front;
        this->back = back;
    }
    void rot(char s){
        if(s == 'E'){
            int tmp = up;
            up = left;
            left = down;
            down = right;
            right = tmp;
        }
        else if(s == 'N'){
            int tmp = up;
            up = front;
            front = down;
            down = back;
            back = tmp;
        }
        else if(s == 'S'){
            int tmp = up;
            up = back;
            back = down;
            down = front;
            front = tmp;
        }
        else if(s == 'W'){
            int tmp = up;
            up = right;
            right = down;
            down = left;
            left = tmp;
        }
        else if(s == 'R'){
            int tmp = front;
            front = right;
            right = back;
            back = left;
            left = tmp;
        }
        else if(s == 'L'){
            int tmp = front;
            front = left;
            left = back;
            back = right;
            right = tmp;
        }
    }
    void Print(){
        cout << this->up << endl;
    }
    void solve(int u,int f){
        if(u==front){
            this->rot('N');
        }
        else if(u==right){
            this->rot('W');
        }
        else if(u==left){
            this->rot('E');
        }
        else if(u==back){
            this->rot('S');
        }
        else if(u==down){
            this->rot('S');
            this->rot('S');
        }
        REP(i,5){
            if(this->front!=f) this->rot('R');
            else break;
        }
    }
    bool operator==(const Dice &another) const{
        return up == another.up && down == another.down && right == another.right && left == another.left && front == another.front && back == another.back;
    }
    bool operator!=(const Dice &another) const{
        return up != another.up || down != another.down || right != another.right || left != another.left || front != another.front || back != another.back;
    }


};


signed main(){
    cin >> n;
    vector<Dice> x;
    int a,b,c,d,e,f;
    REP(i,n){
        cin >> a >> b >> c >> d >> e >> f;
        x.push_back(Dice(a,b,c,d,e,f));
    }
    REP(i,n-1){
        d = x[i].up;
        e = x[i].front;
        x[i].solve(d,e);
        FOR(j,i+1,n){
            x[j].solve(d,e);
            if(x[i]==x[j]){
                print("No");
                return 0;
            }
        }
    }
    print("Yes");
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3128