#include <bits/stdc++.h>

using namespace std;

class Dice{
    public:
        Dice(vector<int> num_array)
            : aspect(num_array){
            }
        void roll_Dice(char c){
            if(c == 'S'){
                int temp = aspect[0]; 
                aspect[0] = aspect[4];
                aspect[4] = aspect[5];
                aspect[5] = aspect[1];
                aspect[1] = temp;
            }else if(c == 'E'){
                int temp = aspect[0];
                aspect[0] = aspect[3];
                aspect[3] = aspect[5];
                aspect[5] = aspect[2];
                aspect[2] = temp;
            }else if(c == 'W'){
                int temp = aspect[0];
                aspect[0] = aspect[2];
                aspect[2] = aspect[5];
                aspect[5] = aspect[3];
                aspect[3] = temp;
            }else if(c == 'N'){
                int temp = aspect[0];
                aspect[0] = aspect[1];
                aspect[1] = aspect[5];
                aspect[5] = aspect[4];
                aspect[4] = temp;
            }
        }
        void yow_dice(){
            int temp = aspect[1];
            aspect[1] = aspect[2];
            aspect[2] = aspect[4];
            aspect[4] = aspect[3];
            aspect[3] = temp;
        }
        int print_eyes(int a){
            return aspect[a];
        }
        int serch_eyes(int objective_eyes){
            for (int i = 0; i < aspect.size(); i++){
                if(aspect[i] == objective_eyes) return i;
            }
        }
    private:
        vector<int> aspect; // 0:upper 1:front 2:right side 3:left side 4: rear side 5: bottom 
};

int main(){
    int num_Dice;
    cin >> num_Dice;
    int counter = 0;
    // --- Dice0 input --- //    
    vector<int> num_array(6);
    vector<Dice> Dice_array;
    for(int i=0;i < 6;i++){
        cin >> num_array[i];
    }
    Dice_array.push_back(num_array);

    for(int k = 1;k < num_Dice;k++){
        // --- Dice i input --- //        
        for(int i=0;i < 6;i++){
            cin >> num_array[i];
        }
        Dice_array.push_back(num_array);

        // --- Dice i roll --- //        
        for(int i = 0;i < 6;i++){
            switch(i){
                case 1:
                    Dice_array[k].roll_Dice('N');
                    break;
                case 2:
                    Dice_array[k].roll_Dice('W');
                    break;
                case 3:
                    Dice_array[k].roll_Dice('N');
                    Dice_array[k].roll_Dice('N');
                    break;
                case 4:
                    Dice_array[k].roll_Dice('W');
                    break;
                case 5:
                    Dice_array[k].roll_Dice('S');
                    break;
            }
            for(int j = 0;j < 4;j++){
                Dice_array[k].yow_dice();
                for(int l = 0;l < k;l++){
                    if(Dice_array[l].print_eyes(0) == Dice_array[k].print_eyes(0) 
                    && Dice_array[l].print_eyes(1) == Dice_array[k].print_eyes(1)
                    && Dice_array[l].print_eyes(2) == Dice_array[k].print_eyes(2)
                    && Dice_array[l].print_eyes(3) == Dice_array[k].print_eyes(3)
                    && Dice_array[l].print_eyes(4) == Dice_array[k].print_eyes(4)
                    && Dice_array[l].print_eyes(5) == Dice_array[k].print_eyes(5))
                    {
                        cout << "No\n";
                        counter++ ;
                        break;
                    }
                }
                if(counter > 0) break;
            }
            if(counter > 0) break;
            }
        if(counter > 0) break;
    }
    
    // --- 
    
    
    if(counter == 0) cout << "Yes\n";
    return 0;
}
 



Measured memory_bytes: 3136