class Dice:

    def __init__(self,t,f,r,l,b,u):

        self.a=[[t,f,r,l,b,u]]

        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}

    def roll(self,d,n):

        self.a[n]=[self.a[n][i] for i in self.direction[d]]

n=int(eval(input()))

for i in range(n):

    if i==0:

        t, f, r, l, b, u = list(map(int, input().split()))

        dice = Dice(t, f, r, l, b, u)

    else:

        a = list(map(int, input().split()))

        dice.a.append(a)

s='SSSWEEE'

w='YYYY'

try:

    for u in range(n - 1):

        for t in range(u + 1, n):

            for j in s:

                for r in w:

                    if dice.a[t] == dice.a[u]:

                        raise Exception

                    dice.roll(r, t)

                dice.roll(j, t)

    else:

        print('Yes')

except:

    print('No')

class Dice:

    def __init__(self,t,f,r,l,b,u):

        self.a=[[t,f,r,l,b,u]]

        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'U':(5,4,2,3,1,0)}

    def dice_tuple(self):

        self.b=tuple(self.a)

    def roll(self,d,n):

        self.a[n]=[self.a[n][i] for i in self.direction[d]]

    def roll2(self,d,n):

        self.a[n]=[self.b[n][i] for i in self.direction[d]]

    def roll_w(self, n):

        self.a[n] = [self.a[n][i] for i in (0, 3, 1, 4, 2, 5)]

n=int(eval(input()))

for i in range(n):

    if i==0:

        t, f, r, l, b, u = list(map(int, input().split()))

        dice = Dice(t, f, r, l, b, u)

    else:

        a = list(map(int, input().split()))

        dice.a.append(a)

dice.dice_tuple()

s='SNEWUU'

try:

    for u in range(n - 1):

        for t in range(u + 1, n):

            for j in s:

                for r in range(4):

                    if dice.a[t] == dice.a[u]:

                        raise Exception

                    dice.roll_w(t)

                dice.roll2(j, t)

    else:

        print('Yes')

except:

    print('No')

class Dice:
    def __init__(self, t, f, r, l, b, u):
        self.a = [[t, f, r, l, b, u]]
        self.direction = {
            "S": (4, 0, 2, 3, 5, 1),
            "N": (1, 5, 2, 3, 0, 4),
            "E": (3, 1, 0, 5, 4, 2),
            "W": (2, 1, 5, 0, 4, 3),
            "Y": (0, 3, 1, 4, 2, 5),
        }

    def roll(self, d, n):
        self.a[n] = [self.a[n][i] for i in self.direction[d]]


n = int(eval(input()))
for i in range(n):
    if i == 0:
        t, f, r, l, b, u = list(map(int, input().split()))
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
s = "SSSWEEE"
w = "YYYY"
try:
    for u in range(n - 1):
        for t in range(u + 1, n):
            for j in s:
                for r in w:
                    if dice.a[t] == dice.a[u]:
                        raise Exception
                    dice.roll(r, t)
                dice.roll(j, t)
    else:
        print("Yes")
except:
    print("No")

class Dice:
    def __init__(self, t, f, r, l, b, u):
        self.a = [[t, f, r, l, b, u]]
        self.direction = {
            "S": (4, 0, 2, 3, 5, 1),
            "N": (1, 5, 2, 3, 0, 4),
            "E": (3, 1, 0, 5, 4, 2),
            "W": (2, 1, 5, 0, 4, 3),
            "U": (5, 4, 2, 3, 1, 0),
        }

    def dice_tuple(self):
        self.b = tuple(self.a)

    def roll(self, d, n):
        self.a[n] = [self.a[n][i] for i in self.direction[d]]

    def roll2(self, d, n):
        self.a[n] = [self.b[n][i] for i in self.direction[d]]

    def roll_w(self, n):
        self.a[n] = [self.a[n][i] for i in (0, 3, 1, 4, 2, 5)]


n = int(eval(input()))
for i in range(n):
    if i == 0:
        t, f, r, l, b, u = list(map(int, input().split()))
        dice = Dice(t, f, r, l, b, u)
    else:
        a = list(map(int, input().split()))
        dice.a.append(a)
dice.dice_tuple()
s = "SNEWUU"
try:
    for u in range(n - 1):
        for t in range(u + 1, n):
            for j in s:
                for r in range(4):
                    if dice.a[t] == dice.a[u]:
                        raise Exception
                    dice.roll_w(t)
                dice.roll2(j, t)
    else:
        print("Yes")
except:
    print("No")

-            "Y": (0, 3, 1, 4, 2, 5), +            "U": (5, 4, 2, 3, 1, 0), + +    def dice_tuple(self): +        self.b = tuple(self.a) + +    def roll2(self, d, n): +        self.a[n] = [self.b[n][i] for i in self.direction[d]] + +    def roll_w(self, n): +        self.a[n] = [self.a[n][i] for i in (0, 3, 1, 4, 2, 5)] -s = "SSSWEEE" -w = "YYYY" +dice.dice_tuple() +s = "SNEWUU" -                for r in w: +                for r in range(4): -                    dice.roll(r, t) -                dice.roll(j, t) +                    dice.roll_w(t) +                dice.roll2(j, t)