from itertools import*

def g():

 n=int(eval(input()))

 a=[[s for s in input().split()]for _ in range(n)]

 for b in a:

  b[3:5]=b[4],b[3]

 t=0

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

  for p in('012345','152043','215304','302541','410352','514320'):

   f=[d[int(i)]for i 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]:t=1

 print((['Yes','No'][t]))

g()

from itertools import*

n=int(eval(input()))

a=[input().split()for _ in[0]*n]

for b in a:

 b[3:5]=b[4],b[3]

def f():

 for d,e in 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[i]for i 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 *


def g():
    n = int(eval(input()))
    a = [[s for s in input().split()] for _ in range(n)]
    for b in a:
        b[3:5] = b[4], b[3]
    t = 0
    for d, e in combinations(a, 2):
        for p in ("012345", "152043", "215304", "302541", "410352", "514320"):
            f = [d[int(i)] for i 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]:
                        t = 1
    print((["Yes", "No"][t]))


g()

from itertools import *

n = int(eval(input()))
a = [input().split() for _ in [0] * n]
for b in a:
    b[3:5] = b[4], b[3]


def f():
    for d, e in 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[i] for i 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()))

+n = int(eval(input())) +a = [input().split() for _ in [0] * n] +for b in a: +    b[3:5] = b[4], b[3] -def g(): -    n = int(eval(input())) -    a = [[s for s in input().split()] for _ in range(n)] -    for b in a: -        b[3:5] = b[4], b[3] -    t = 0 + +def f(): -        for p in ("012345", "152043", "215304", "302541", "410352", "514320"): -            f = [d[int(i)] for i in p] +        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[i] for i in p] -                        t = 1 -    print((["Yes", "No"][t])) +                        return "No" +    return "Yes" -g() +print((f()))