/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_D
 */
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class Die
{
    enum fname {
        top, front, right, left, back, bottom,
    };

    vector<int> faces;
    map<fname, int> f2i;

    bool
    check_rest(Die &x)
    {
        if (faces[f2i[right] ] != x.Right() ) { return false; }
        if (faces[f2i[left]  ] != x.Left()  ) { return false; }
        if (faces[f2i[back]  ] != x.Back()  ) { return false; }
        if (faces[f2i[bottom]] != x.Bottom()) { return false; }
        return true;
    }

    bool
    check_top(Die &x)
    {
        turn_s();
        const string roll = "EEEE";
        bool ret = false;
        for (auto it : roll) {
            if (faces[f2i[top]] == x.Top()) {
                ret |= check_rest(x);
            }
            turn(it);
        }
        turn_n();
        return ret;
    }

    void
    turn_e() {
        int tmp = f2i[top];
        f2i[top] = f2i[left];
        f2i[left] = f2i[bottom];
        f2i[bottom] = f2i[right];
        f2i[right] = tmp;
    }

    void
    turn_n() {
        int tmp = f2i[top];
        f2i[top] = f2i[front];
        f2i[front] = f2i[bottom];
        f2i[bottom] = f2i[back];
        f2i[back] = tmp;
    }

    void
    turn_s() {
        int tmp = f2i[top];
        f2i[top] = f2i[back];
        f2i[back] = f2i[bottom];
        f2i[bottom] = f2i[front];
        f2i[front] = tmp;
    }

    void
    turn_w() {
        int tmp = f2i[top];
        f2i[top] = f2i[right];
        f2i[right] = f2i[bottom];
        f2i[bottom] = f2i[left];
        f2i[left] = tmp;
    }

public:
    Die()
    {
        faces.reserve(6);

        f2i.emplace(top, 0);
        f2i.emplace(front, 1);
        f2i.emplace(right, 2);
        f2i.emplace(left, 3);
        f2i.emplace(back, 4);
        f2i.emplace(bottom, 5);
    }

    ~Die()
    {
        faces.clear();
        f2i.clear();
    }

    void
    read_faces(istream &is) {
        for (int i = 0; i < 6; i++) {
            is >> faces[i]; is.ignore();
        }
    }

    bool
    operator==(Die &x) {
        const string aface = "NENENE";
        bool ret = false;
        for (auto it : aface) {
            if (faces[f2i[top]] == x.Front()) {
                ret |= check_top(x);
            }
            turn(it);
        }
        return ret;
    }

    void
    turn(const char c) {
        switch (c) {
          case 'N':
            turn_n();
            break;
          case 'E':
            turn_e();
            break;
          case 'S':
            turn_s();
            break;
          case 'W':
            turn_w();
            break;
        }
    }

    int Top()    { return faces[f2i[top]   ]; }
    int Front()  { return faces[f2i[front] ]; }
    int Right()  { return faces[f2i[right] ]; }
    int Left()   { return faces[f2i[left]  ]; }
    int Back()   { return faces[f2i[back]  ]; }
    int Bottom() { return faces[f2i[bottom]]; }
};

template <typename T>
bool
all_different(vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; i++) {
        for (int j = i + 1; j < v.size(); j++) {
            if (v[i] == v[j]) { return false; }
        }
    }
    return true;
}

int
main()
{
    ios::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    vector<Die> vd(n);
    for (int i = 0; i < n; i++) {
        vd[i].read_faces(cin);
    }

    cout << (all_different<Die>(vd) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3220