class Dice:

    def __init__(self):

        self.faces=[]



    def rotate(self, direction):

        tmp = self.faces.copy()



        if direction =="N":

            self.faces[5-1] = tmp[1-1]

            self.faces[1-1] = tmp[2-1]

            self.faces[2-1] = tmp[6-1]

            self.faces[6-1] = tmp[5-1]

        if direction =="S":

            self.faces[5-1] = tmp[6-1]

            self.faces[1-1] = tmp[5-1]

            self.faces[2-1] = tmp[1-1]

            self.faces[6-1] = tmp[2-1]

        if direction =="W":

            self.faces[4-1] = tmp[1-1]

            self.faces[1-1] = tmp[3-1]

            self.faces[3-1] = tmp[6-1]

            self.faces[6-1] = tmp[4-1]

        if direction =="E":

            self.faces[3-1] = tmp[1-1]

            self.faces[1-1] = tmp[4-1]

            self.faces[4-1] = tmp[6-1]

            self.faces[6-1] = tmp[3-1]

        return 0



    def spin(self):

        self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\

        self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]



        return 0



dices = []

lines = int(input())

for i in range(lines):

    dices.append(Dice())

    dices[i].faces=[int(x) for x in input().split(" ")]



for i, d1 in enumerate(dices):

    for d2 in dices[i+1 :]:

        for _ in range(3):

            for _ in range(4):

                for ___ in range(4):

                    #print("d1: {}".format(d1.faces))

                    #print("d2: {}".format(d2.faces))

                    if d1.faces == d2.faces:

                        print("No")

                        exit()

                    d2.spin()

                d2.rotate("W")

            d2.rotate("N")



print("Yes")

def roll(l, command):

    '''

    return rolled list



    l : string list

    command: string

    '''

    res = []

    i = -1

    if command =='N':

        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]

    if command =='S':

        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]

    if command =='E':

        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]

    if command =='W':

        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]



    return res



def spin(l):

    '''

    return right sppined list



    l : string list

    '''



    i = -1

    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]



    return res

def has_same_faces(a, b):

    '''

    check if all elements of a are equel to those of b.

    a : string list

    b : string list

    '''

    return set(a) == set(b)



def is_identical_lists(a, b):

    for x, y in zip(a, b):

        if x != y:

            return False



    return True



def check_two_dice(a, b):

    if not has_same_faces(a, b):

        return False

    

    orig_a = a[:]



    #roll and spin to check

    for i in range(6):

        if 1 <= i <= 3:

            a = roll(a, "N")

        elif i == 4:

            pass

            a = orig_a[:]

            a = roll(a, "W")

        elif i == 5:

            a = orig_a[:]

            a = roll(a, "E")



        # spin 4 times

        for _ in range(4): #spin 3 times

            a = spin(a)

            if is_identical_lists(a, b):

                return True

        

    return False



def check_all_different(dice):

    '''

    if all dice are different, return True



    dice : string list



    '''

    for i in range(len(dice)):

        if i == 0:

            continue

        for j in range(i):

            res = check_two_dice(dice[i], dice[j])



            if res:

                return False

    

    return True





if __name__ == "__main__":

    res = False

    n = int(input())

    dice = []

    for _ in range(n): 

        dice.append(input().split())



    res = check_all_different(dice)



    print("Yes") if res else print("No")







class Dice:
    def __init__(self):
        self.faces = []

    def rotate(self, direction):
        tmp = self.faces.copy()
        if direction == "N":
            self.faces[5 - 1] = tmp[1 - 1]
            self.faces[1 - 1] = tmp[2 - 1]
            self.faces[2 - 1] = tmp[6 - 1]
            self.faces[6 - 1] = tmp[5 - 1]
        if direction == "S":
            self.faces[5 - 1] = tmp[6 - 1]
            self.faces[1 - 1] = tmp[5 - 1]
            self.faces[2 - 1] = tmp[1 - 1]
            self.faces[6 - 1] = tmp[2 - 1]
        if direction == "W":
            self.faces[4 - 1] = tmp[1 - 1]
            self.faces[1 - 1] = tmp[3 - 1]
            self.faces[3 - 1] = tmp[6 - 1]
            self.faces[6 - 1] = tmp[4 - 1]
        if direction == "E":
            self.faces[3 - 1] = tmp[1 - 1]
            self.faces[1 - 1] = tmp[4 - 1]
            self.faces[4 - 1] = tmp[6 - 1]
            self.faces[6 - 1] = tmp[3 - 1]
        return 0

    def spin(self):
        self.faces[4 - 1], self.faces[2 - 1], self.faces[5 - 1], self.faces[3 - 1] = (
            self.faces[2 - 1],
            self.faces[3 - 1],
            self.faces[4 - 1],
            self.faces[5 - 1],
        )
        return 0


dices = []
lines = int(input())
for i in range(lines):
    dices.append(Dice())
    dices[i].faces = [int(x) for x in input().split(" ")]
for i, d1 in enumerate(dices):
    for d2 in dices[i + 1 :]:
        for _ in range(3):
            for _ in range(4):
                for ___ in range(4):
                    # print("d1: {}".format(d1.faces))
                    # print("d2: {}".format(d2.faces))
                    if d1.faces == d2.faces:
                        print("No")
                        exit()
                    d2.spin()
                d2.rotate("W")
            d2.rotate("N")
print("Yes")

def roll(l, command):
    """
    return rolled list
    l : string list
    command: string
    """
    res = []
    i = -1
    if command == "N":
        res = [l[i + 2], l[i + 6], l[i + 3], l[i + 4], l[i + 1], l[i + 5]]
    if command == "S":
        res = [l[i + 5], l[i + 1], l[i + 3], l[i + 4], l[i + 6], l[i + 2]]
    if command == "E":
        res = [l[i + 4], l[i + 2], l[i + 1], l[i + 6], l[i + 5], l[i + 3]]
    if command == "W":
        res = [l[i + 3], l[i + 2], l[i + 6], l[i + 1], l[i + 5], l[i + 4]]
    return res


def spin(l):
    """
    return right sppined list
    l : string list
    """
    i = -1
    res = [l[i + 1], l[i + 3], l[i + 5], l[i + 2], l[i + 4], l[i + 6]]
    return res


def has_same_faces(a, b):
    """
    check if all elements of a are equel to those of b.
    a : string list
    b : string list
    """
    return set(a) == set(b)


def is_identical_lists(a, b):
    for x, y in zip(a, b):
        if x != y:
            return False
    return True


def check_two_dice(a, b):
    if not has_same_faces(a, b):
        return False
    orig_a = a[:]
    # roll and spin to check
    for i in range(6):
        if 1 <= i <= 3:
            a = roll(a, "N")
        elif i == 4:
            pass
            a = orig_a[:]
            a = roll(a, "W")
        elif i == 5:
            a = orig_a[:]
            a = roll(a, "E")
        # spin 4 times
        for _ in range(4):  # spin 3 times
            a = spin(a)
            if is_identical_lists(a, b):
                return True
    return False


def check_all_different(dice):
    """
    if all dice are different, return True
    dice : string list
    """
    for i in range(len(dice)):
        if i == 0:
            continue
        for j in range(i):
            res = check_two_dice(dice[i], dice[j])
            if res:
                return False
    return True


if __name__ == "__main__":
    res = False
    n = int(input())
    dice = []
    for _ in range(n):
        dice.append(input().split())
    res = check_all_different(dice)
    print("Yes") if res else print("No")

-class Dice: -    def __init__(self): -        self.faces = [] - -    def rotate(self, direction): -        tmp = self.faces.copy() -        if direction == "N": -            self.faces[5 - 1] = tmp[1 - 1] -            self.faces[1 - 1] = tmp[2 - 1] -            self.faces[2 - 1] = tmp[6 - 1] -            self.faces[6 - 1] = tmp[5 - 1] -        if direction == "S": -            self.faces[5 - 1] = tmp[6 - 1] -            self.faces[1 - 1] = tmp[5 - 1] -            self.faces[2 - 1] = tmp[1 - 1] -            self.faces[6 - 1] = tmp[2 - 1] -        if direction == "W": -            self.faces[4 - 1] = tmp[1 - 1] -            self.faces[1 - 1] = tmp[3 - 1] -            self.faces[3 - 1] = tmp[6 - 1] -            self.faces[6 - 1] = tmp[4 - 1] -        if direction == "E": -            self.faces[3 - 1] = tmp[1 - 1] -            self.faces[1 - 1] = tmp[4 - 1] -            self.faces[4 - 1] = tmp[6 - 1] -            self.faces[6 - 1] = tmp[3 - 1] -        return 0 - -    def spin(self): -        self.faces[4 - 1], self.faces[2 - 1], self.faces[5 - 1], self.faces[3 - 1] = ( -            self.faces[2 - 1], -            self.faces[3 - 1], -            self.faces[4 - 1], -            self.faces[5 - 1], -        ) -        return 0 +def roll(l, command): +    """ +    return rolled list +    l : string list +    command: string +    """ +    res = [] +    i = -1 +    if command == "N": +        res = [l[i + 2], l[i + 6], l[i + 3], l[i + 4], l[i + 1], l[i + 5]] +    if command == "S": +        res = [l[i + 5], l[i + 1], l[i + 3], l[i + 4], l[i + 6], l[i + 2]] +    if command == "E": +        res = [l[i + 4], l[i + 2], l[i + 1], l[i + 6], l[i + 5], l[i + 3]] +    if command == "W": +        res = [l[i + 3], l[i + 2], l[i + 6], l[i + 1], l[i + 5], l[i + 4]] +    return res -dices = [] -lines = int(input()) -for i in range(lines): -    dices.append(Dice()) -    dices[i].faces = [int(x) for x in input().split(" ")] -for i, d1 in enumerate(dices): -    for d2 in dices[i + 1 :]: -        for _ in range(3): -            for _ in range(4): -                for ___ in range(4): -                    # print("d1: {}".format(d1.faces)) -                    # print("d2: {}".format(d2.faces)) -                    if d1.faces == d2.faces: -                        print("No") -                        exit() -                    d2.spin() -                d2.rotate("W") -            d2.rotate("N") -print("Yes") +def spin(l): +    """ +    return right sppined list +    l : string list +    """ +    i = -1 +    res = [l[i + 1], l[i + 3], l[i + 5], l[i + 2], l[i + 4], l[i + 6]] +    return res + + +def has_same_faces(a, b): +    """ +    check if all elements of a are equel to those of b. +    a : string list +    b : string list +    """ +    return set(a) == set(b) + + +def is_identical_lists(a, b): +    for x, y in zip(a, b): +        if x != y: +            return False +    return True + + +def check_two_dice(a, b): +    if not has_same_faces(a, b): +        return False +    orig_a = a[:] +    # roll and spin to check +    for i in range(6): +        if 1 <= i <= 3: +            a = roll(a, "N") +        elif i == 4: +            pass +            a = orig_a[:] +            a = roll(a, "W") +        elif i == 5: +            a = orig_a[:] +            a = roll(a, "E") +        # spin 4 times +        for _ in range(4):  # spin 3 times +            a = spin(a) +            if is_identical_lists(a, b): +                return True +    return False + + +def check_all_different(dice): +    """ +    if all dice are different, return True +    dice : string list +    """ +    for i in range(len(dice)): +        if i == 0: +            continue +        for j in range(i): +            res = check_two_dice(dice[i], dice[j]) +            if res: +                return False +    return True + + +if __name__ == "__main__": +    res = False +    n = int(input()) +    dice = [] +    for _ in range(n): +        dice.append(input().split()) +    res = check_all_different(dice) +    print("Yes") if res else print("No")