from itertools import*

n=int(eval(input()))

a=[list(map(int,input().split()))for _ in range(n)]

def f():

 for p,q in list(combinations(a,2)):

  d=p[:];d[3],d[4]=d[4],d[3]

  e=q[:];e[3],e[4]=e[4],e[3]

  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):

   f=[d[k]for k in p]

   if f[0]==e[0]and f[5]==e[5]:

    f=f[1:5]*2

    for k in range(4):

     if f[k:k+4]==e[1:5]:return'No'

 return'Yes'

print((f()))

from itertools import*

n=int(eval(input()))

a=[list(map(int,input().split()))for _ in range(n)]

for k in range(n):

 b=a[k];b[3],b[4]=b[4],b[3]

def f():

 for d,e in list(combinations(a,2)):

  for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):

   f=[d[k]for k in p]

   if f[0]==e[0]and f[5]==e[5]:

    f=f[1:5]*2

    for k in range(4):

     if f[k:k+4]==e[1:5]:return'No'

 return'Yes'

print((f()))

from itertools import *

n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]


def f():
    for p, q in list(combinations(a, 2)):
        d = p[:]
        d[3], d[4] = d[4], d[3]
        e = q[:]
        e[3], e[4] = e[4], e[3]
        for p in (
            [0, 1, 2, 3, 4, 5],
            [1, 5, 2, 0, 4, 3],
            [2, 1, 5, 3, 0, 4],
            [3, 0, 2, 5, 4, 1],
            [4, 1, 0, 3, 5, 2],
            [5, 1, 4, 3, 2, 0],
        ):
            f = [d[k] for k in p]
            if f[0] == e[0] and f[5] == e[5]:
                f = f[1:5] * 2
                for k in range(4):
                    if f[k : k + 4] == e[1:5]:
                        return "No"
    return "Yes"


print((f()))

from itertools import *

n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
for k in range(n):
    b = a[k]
    b[3], b[4] = b[4], b[3]


def f():
    for d, e in list(combinations(a, 2)):
        for p in (
            [0, 1, 2, 3, 4, 5],
            [1, 5, 2, 0, 4, 3],
            [2, 1, 5, 3, 0, 4],
            [3, 0, 2, 5, 4, 1],
            [4, 1, 0, 3, 5, 2],
            [5, 1, 4, 3, 2, 0],
        ):
            f = [d[k] for k in p]
            if f[0] == e[0] and f[5] == e[5]:
                f = f[1:5] * 2
                for k in range(4):
                    if f[k : k + 4] == e[1:5]:
                        return "No"
    return "Yes"


print((f()))

+for k in range(n): +    b = a[k] +    b[3], b[4] = b[4], b[3] -    for p, q in list(combinations(a, 2)): -        d = p[:] -        d[3], d[4] = d[4], d[3] -        e = q[:] -        e[3], e[4] = e[4], e[3] +    for d, e in list(combinations(a, 2)):