#include <iostream>
#include <vector>
#include <array>

class Dice {
    using dice_t = std::array<int,6>;
    enum class Dir : int {north, east, south, west};
    dice_t dice{};
    void roll(const Dir);
    bool operator==(const Dice&) const;
public:
    static constexpr int f_top{0}, f_south{1}, f_east{2}, f_west{3}, f_north{4}, f_bottom{5};
    Dice() { Dice{dice_t{1,2,3,4,5,6}}; };
    Dice(const dice_t& d) { for(auto i=0; i<6; i++) dice[i]=d[i]; }
    ~Dice(){}
    void roll(const std::string&);
    void rotate_parallel_to_ground_at_clockward();
    bool is_same_as(const Dice&);
    int get_face(const int) const;
};
void Dice::roll(const Dir dir) {
    int rep_face1{}, rep_face2{};
    switch(dir) {
    case Dir::north: rep_face1=f_north; rep_face2=f_south; break;
    case Dir::east:  rep_face1=f_east;  rep_face2=f_west;  break;
    case Dir::south: rep_face1=f_south; rep_face2=f_north; break;
    case Dir::west:  rep_face1=f_west;  rep_face2=f_east;  break;
    default:
        return;
    }
    int prevface{dice[f_bottom]};
    dice[f_bottom ] = dice[rep_face1];
    dice[rep_face1] = dice[f_top    ];
    dice[f_top    ] = dice[rep_face2];
    dice[rep_face2] = prevface;
}
void Dice::roll(const std::string& s) {
    for(auto c : s) {
        switch(c) {
        case 'N': roll(Dir::north); break;
        case 'E': roll(Dir::east ); break;
        case 'S': roll(Dir::south); break;
        case 'W': roll(Dir::west ); break;
        default:
            break;
        }
    }
}
void Dice::rotate_parallel_to_ground_at_clockward() {
    int prevface{dice[f_north]};
    dice[f_north] = dice[f_west ];
    dice[f_west ] = dice[f_south];
    dice[f_south] = dice[f_east ];
    dice[f_east ] = prevface;
}
bool Dice::operator==(const Dice& d) const {
    return d.get_face(f_bottom) == dice[f_bottom] &&
           d.get_face(f_north ) == dice[f_north ] &&
           d.get_face(f_east  ) == dice[f_east  ] &&
           d.get_face(f_south ) == dice[f_south ] &&
           d.get_face(f_west  ) == dice[f_west  ] &&
           d.get_face(f_top   ) == dice[f_top   ];
}
bool Dice::is_same_as(const Dice& d) {
    Dice dd{dice};
    for(auto i=0; i<4; i++) {
        for(auto j=0; j<4; j++) {
            if(d==dd) return true;
            dd.rotate_parallel_to_ground_at_clockward();
        }
        dd.roll(Dir::north);
    }
    dd.roll(Dir::east);
    for(auto i=0; i<4; i++) {
        if(d==dd) return true;
        dd.rotate_parallel_to_ground_at_clockward();
    }
    dd.roll(Dir::east);
    dd.roll(Dir::east);
    for(auto i=0; i<4; i++) {
        if(d==dd) return true;
        dd.rotate_parallel_to_ground_at_clockward();
    }
    return false;    
}
int Dice::get_face(const int face) const {
    return dice[face];
}

int main() {
    using dice_faces_t = std::array<int,6>;
    dice_faces_t dice_faces{};
    std::vector<Dice> dices{};
    int n{}; std::cin >> n;
    for(auto i=0; i<n; i++) {
        for(auto j=0; j<6; j++) { std::cin >> dice_faces[j]; }
        dices.push_back(Dice{dice_faces});
    }
    for(auto i=1; i<n; i++) {
        Dice& d = dices[i];
        for(auto j=0; j<i; j++) {
            if(d.is_same_as(dices[j])) {
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "Yes" << std::endl;
}



Measured memory_bytes: 3128