def move(d, r):

    if r == 'N':

        return (d[1], d[5], d[2], d[3], d[0], d[4])

    if r == 'E':

        return (d[3], d[1], d[0], d[5], d[4], d[2])

    if r == 'W':

        return (d[2], d[1], d[5], d[0], d[4], d[3])

    if r == 'S':

        return (d[4], d[0], d[2], d[3], d[5], d[1])

    return d

     

def gen_all(dice_1):

    dice = {dice_1}

    while True:

        dice2 = {move(d,r) for d in dice for r in list("NEWS")}.union(dice)

        if dice == dice2: break

        dice = dice2

    return dice    





n = int(eval(input()))

count = 0

dice = [0 for i in range(n)]





for i in range(n):

    dice[i] = tuple(map(int,input().split()))



for i in range(n):

    for k in range(i):

        if count == 1: break

        if dice[i] in gen_all(dice[k]):

            print("No")

            count = 1

            break

if count == 0:

    print("Yes")   

    



    

    

    
n = int(eval(input()))



def rot(dice,rotation):

    if rotation == "E":

        dice = (dice[3],dice[1],dice[0],dice[5],dice[4],dice[2])

    elif rotation == "W":

        dice = (dice[2],dice[1],dice[5],dice[0],dice[4],dice[3])

    elif rotation == "N":

        dice = (dice[1],dice[5],dice[2],dice[3],dice[0],dice[4])

    elif rotation == "S":

        dice = (dice[4],dice[0],dice[2],dice[3],dice[5],dice[1])

    return dice



def make_all_pattern(dice):

    pattern = {dice}

    pattern2 = pattern

    while True:

        pattern2 = pattern.union({rot(d,r) for d in pattern for r in list("NEWS")})

        if pattern2 == pattern:

            break

        pattern = pattern2

    return pattern



dice = [0 for i in range(n)]

for i in range(n):

    dice[i] = tuple(map(int,input().split()))





pattern = set()

for i in range(n-1):

    pattern = pattern.union(make_all_pattern(dice[i]))

    if dice[i+1] in pattern:

        print("No")

        break



else:

    print("Yes")

    
def move(d, r):
    if r == "N":
        return (d[1], d[5], d[2], d[3], d[0], d[4])
    if r == "E":
        return (d[3], d[1], d[0], d[5], d[4], d[2])
    if r == "W":
        return (d[2], d[1], d[5], d[0], d[4], d[3])
    if r == "S":
        return (d[4], d[0], d[2], d[3], d[5], d[1])
    return d


def gen_all(dice_1):
    dice = {dice_1}
    while True:
        dice2 = {move(d, r) for d in dice for r in list("NEWS")}.union(dice)
        if dice == dice2:
            break
        dice = dice2
    return dice


n = int(eval(input()))
count = 0
dice = [0 for i in range(n)]
for i in range(n):
    dice[i] = tuple(map(int, input().split()))
for i in range(n):
    for k in range(i):
        if count == 1:
            break
        if dice[i] in gen_all(dice[k]):
            print("No")
            count = 1
            break
if count == 0:
    print("Yes")

n = int(eval(input()))


def rot(dice, rotation):
    if rotation == "E":
        dice = (dice[3], dice[1], dice[0], dice[5], dice[4], dice[2])
    elif rotation == "W":
        dice = (dice[2], dice[1], dice[5], dice[0], dice[4], dice[3])
    elif rotation == "N":
        dice = (dice[1], dice[5], dice[2], dice[3], dice[0], dice[4])
    elif rotation == "S":
        dice = (dice[4], dice[0], dice[2], dice[3], dice[5], dice[1])
    return dice


def make_all_pattern(dice):
    pattern = {dice}
    pattern2 = pattern
    while True:
        pattern2 = pattern.union({rot(d, r) for d in pattern for r in list("NEWS")})
        if pattern2 == pattern:
            break
        pattern = pattern2
    return pattern


dice = [0 for i in range(n)]
for i in range(n):
    dice[i] = tuple(map(int, input().split()))
pattern = set()
for i in range(n - 1):
    pattern = pattern.union(make_all_pattern(dice[i]))
    if dice[i + 1] in pattern:
        print("No")
        break
else:
    print("Yes")

-def move(d, r): -    if r == "N": -        return (d[1], d[5], d[2], d[3], d[0], d[4]) -    if r == "E": -        return (d[3], d[1], d[0], d[5], d[4], d[2]) -    if r == "W": -        return (d[2], d[1], d[5], d[0], d[4], d[3]) -    if r == "S": -        return (d[4], d[0], d[2], d[3], d[5], d[1]) -    return d +n = int(eval(input())) -def gen_all(dice_1): -    dice = {dice_1} -    while True: -        dice2 = {move(d, r) for d in dice for r in list("NEWS")}.union(dice) -        if dice == dice2: -            break -        dice = dice2 +def rot(dice, rotation): +    if rotation == "E": +        dice = (dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]) +    elif rotation == "W": +        dice = (dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]) +    elif rotation == "N": +        dice = (dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]) +    elif rotation == "S": +        dice = (dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]) -n = int(eval(input())) -count = 0 +def make_all_pattern(dice): +    pattern = {dice} +    pattern2 = pattern +    while True: +        pattern2 = pattern.union({rot(d, r) for d in pattern for r in list("NEWS")}) +        if pattern2 == pattern: +            break +        pattern = pattern2 +    return pattern + + -for i in range(n): -    for k in range(i): -        if count == 1: -            break -        if dice[i] in gen_all(dice[k]): -            print("No") -            count = 1 -            break -if count == 0: +pattern = set() +for i in range(n - 1): +    pattern = pattern.union(make_all_pattern(dice[i])) +    if dice[i + 1] in pattern: +        print("No") +        break +else: