#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
class cDie
{
  private:
    std::array<int64_t, 6> aEye;

  public:
    cDie(std::array<int64_t, 6> aEye)
    {
        cDie::aEye = aEye;
    }
    void fE()
    {
        int64_t t = aEye[0];
        aEye[0] = aEye[3];
        aEye[3] = aEye[5];
        aEye[5] = aEye[2];
        aEye[2] = t;
    }
    void fW()
    {
        fE();
        fE();
        fE();
    }
    void fN()
    {
        int64_t t = aEye[0];
        aEye[0] = aEye[1];
        aEye[1] = aEye[5];
        aEye[5] = aEye[4];
        aEye[4] = t;
    }
    void fS()
    {
        fN();
        fN();
        fN();
    }
    size_t top()
    {
        return aEye[0];
    }
    void top(size_t i)
    {
        aEye[0] = i;
    }
};
int main()
{
    std::cout << std::setprecision(16);

    if ([] {
            std::vector<cDie> vDie;
            int64_t n;
            std::cin >> n;
            for (int64_t k = 0; k < n; k++)
            {
                int64_t i1, i2, i3, i4, i5, i6;
                std::cin >> i1 >> i2 >> i3 >> i4 >> i5 >> i6;
                vDie.push_back(cDie({i1, i2, i3, i4, i5, i6}));
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    cDie die1Org = vDie[i];
                    cDie die2Org = vDie[j];
                    if ([&] {
                            for (auto it2 : std::string("EEENNNN"))
                            {
                                if (it2 == 'E')
                                {
                                    die2Org.fE();
                                }
                                else if (it2 == 'N')
                                {
                                    die2Org.fN();
                                }
                                cDie die2 = die2Org;
                                cDie die1 = die1Org;
                                int64_t q1 = die2.top();
                                die2.fN();
                                int64_t q2 = die2.top();
                                die2.fS();
                                if ([&] {
                                        for (auto it : std::string("EEENNNN"))
                                        {
                                            if (die1.top() == q1)
                                            {
                                                return true;
                                            }
                                            else if (it == 'E')
                                            {
                                                die1.fE();
                                            }
                                            else if (it == 'N')
                                            {
                                                die1.fN();
                                            }
                                        }
                                        return false;
                                    }())
                                {
                                    if ([&] {
                                            die1.fS();
                                            if (die1.top() == q2)
                                            {
                                                die1.fS();
                                                die1.fE();
                                                die1.fE();
                                                return true;
                                            }
                                            die1.fN();
                                            die1.fN();
                                            if (die1.top() == q2)
                                            {
                                                die1.fS();
                                                return true;
                                            }
                                            die1.fS();
                                            die1.fW();
                                            if (die1.top() == q2)
                                            {
                                                die1.fS();
                                                die1.fE();
                                                return true;
                                            }
                                            die1.fE();
                                            die1.fE();
                                            if (die1.top() == q2)
                                            {
                                                die1.fS();
                                                die1.fW();
                                                return true;
                                            }
                                            die1.fW();
                                            return false;
                                        }())
                                    {
                                        if ([&] {
                                                for (auto it : std::string("EEENNN"))
                                                {
                                                    if (it == 'E')
                                                    {
                                                        die1.fE();
                                                        die2.fE();
                                                    }
                                                    else if (it == 'N')
                                                    {
                                                        die1.fN();
                                                        die2.fN();
                                                    }
                                                    if (die1.top() != die2.top())
                                                    {
                                                        return false;
                                                    }
                                                }
                                                return true;
                                            }())
                                        {
                                            return true;
                                        }
                                        else
                                        {
                                        }
                                    }
                                    else
                                    {
                                    }
                                }
                                else
                                {
                                }
                            }
                            return false;
                        }())
                    {
                        return false;
                    }
                    else
                    {
                    }
                }
            }
            return true;
        }())
    {
        std::cout << "Yes\n";
    }
    else
    {
        std::cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 3228