#-*- coding:utf-8 -*-
import sys
n = input()
rolls =[]
for x in xrange(n):
    rolls.append(raw_input().split())
#??????????????¨??????????????????????????????
#?????´????????????????????¨??????????????£???????????§??????
for l1 in xrange(n):
    for l2 in xrange(n):
        #??????????????????????????????
        #?????????????????????????????´????????????????????????????????????????????£????????????????????????
        if l1==l2:
            break
        rolls_copy = rolls
        testpare = (rolls_copy[l1][0],rolls_copy[l1][5])
        testparerev = (rolls_copy[l1][5],rolls_copy[l1][0])
        rolls2pare = [(rolls_copy[l2][0],rolls_copy[l2][5]),(rolls_copy[l2][2],rolls_copy[l2][3]),(rolls_copy[l2][1],rolls_copy[l2][4])]
        #??????????????¢????????¢??§?????´??????????????????????????????????¢????
        #??¨??¨????????¢?????£????????????????????´???????????¢???3????????¨??????????¢????????????????????????????
        if testpare in rolls2pare:
            pareps = rolls2pare.index(testpare)
            revflag = False
        elif testparerev in rolls2pare:
            pareps = rolls2pare.index(testparerev)
            revflag = True
        else:
            break
        #?¬???????????????¢??\????????¨????????????????????£??????????¢????
        #??????????????????????????????
        li1 = [rolls_copy[l1][1],rolls_copy[l1][2],rolls_copy[l1][4],rolls_copy[l1][3]]
        # print pareps
        if pareps==0:
            if revflag:
                tmp = rolls_copy[l2][2]
                rolls_copy[l2][2] = rolls_copy[l2][3]
                rolls_copy[l2][3] = tmp
            li2 = [rolls_copy[l2][1],rolls_copy[l2][2],rolls_copy[l2][4],rolls_copy[l2][3]]
        elif pareps==1:
            if revflag:
                tmp = rolls_copy[l2][1]
                rolls_copy[l2][1] = rolls_copy[l2][4]
                rolls_copy[l2][4] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][1],rolls_copy[l2][5],rolls_copy[l2][4]]
        elif pareps==2:
            if revflag:
                tmp = rolls_copy[l2][0]
                rolls_copy[l2][0] = rolls_copy[l2][5]
                rolls_copy[l2][5] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][3],rolls_copy[l2][5],rolls_copy[l2][2]]
        else:
            break
        #?????????????????´?¢????
        # print li1
        # print li2
        i=0
        j=li2.index(li1[0])
        matchflag = True#else??\??£???????????´?????????
        for x in xrange(4):
            # print "%s : %s"%(li1[i],li2[j])
            if li1[i]==li2[j]:
                j+=1
                i+=1
            else:
                matchflag =False
                break
            if i>3:
                i=0
            if j>3:
                j=0
        if matchflag:
            print "No"
            sys.exit(0)
print "Yes"

### FIXED CODE ###

#-*- coding:utf-8 -*-
import sys
n = input()
rolls =[]
for x in xrange(n):
    rolls.append(raw_input().split())
def pareExist(li1,li2):
    for x in xrange(3):
        if set(rolls1pare[x]) not in map(set,rolls2pare):
            return False
    return True
#??????????????¨??????????????????????????????
#?????´????????????????????¨??????????????£???????????§??????
for l1 in xrange(n):
    for l2 in xrange(n):
        #??????????????????????????????
        #?????????????????????????????´????????????????????????????????????????????£????????????????????????
        if l1==l2:
            break
        rolls_copy = rolls
        #??¨??¨????????¢?????£????????????????????´???????????¢???3????????¨??????????¢????
        rolls1pare = [(rolls_copy[l1][0],rolls_copy[l1][5]),(rolls_copy[l1][2],rolls_copy[l1][3]),(rolls_copy[l1][1],rolls_copy[l1][4])]
        testpare = (rolls_copy[l1][0],rolls_copy[l1][5])
        testparerev = (rolls_copy[l1][5],rolls_copy[l1][0])
        rolls2pare = [(rolls_copy[l2][0],rolls_copy[l2][5]),(rolls_copy[l2][2],rolls_copy[l2][3]),(rolls_copy[l2][1],rolls_copy[l2][4])]
        # print rolls1pare
        # print rolls2pare
        #?????????????????¢???????????°?????´?????????????????????
        if not pareExist(rolls1pare,rolls2pare):
            break
        #??????????????¢????????¢??§?????´??????????????????????????????????¢????
        if testpare in rolls2pare:
            pareps = rolls2pare.index(testpare)
            revflag = False
        elif testparerev in rolls2pare:
            pareps = rolls2pare.index(testparerev)
            revflag = True
        else:
            break
        #?¬???????????????¢??\????????¨????????????????????£??????????¢????
        #??????????????????????????????
        li1 = [rolls_copy[l1][1],rolls_copy[l1][2],rolls_copy[l1][4],rolls_copy[l1][3]]
        # print pareps
        if pareps==0:
            if revflag:
                tmp = rolls_copy[l2][2]
                rolls_copy[l2][2] = rolls_copy[l2][3]
                rolls_copy[l2][3] = tmp
            li2 = [rolls_copy[l2][1],rolls_copy[l2][2],rolls_copy[l2][4],rolls_copy[l2][3]]
        elif pareps==1:
            if revflag:
                tmp = rolls_copy[l2][1]
                rolls_copy[l2][1] = rolls_copy[l2][4]
                rolls_copy[l2][4] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][1],rolls_copy[l2][5],rolls_copy[l2][4]]
        elif pareps==2:
            if revflag:
                tmp = rolls_copy[l2][0]
                rolls_copy[l2][0] = rolls_copy[l2][5]
                rolls_copy[l2][5] = tmp
            li2 = [rolls_copy[l2][0],rolls_copy[l2][3],rolls_copy[l2][5],rolls_copy[l2][2]]
        else:
            break
        #?????????????????´?¢????
        # print li1
        # print li2
        i=0
        j=li2.index(li1[0])
        matchflag = True#else??\??£???????????´?????????
        for x in xrange(4):
            # print "%s : %s"%(li1[i],li2[j])
            if li1[i]==li2[j]:
                j+=1
                i+=1
            else:
                matchflag =False
                break
            if i>3:
                i=0
            if j>3:
                j=0
        if matchflag:
            print "No"
            sys.exit(0)
print "Yes"