#サイコロの問題Cのはずがミスって編集してD問題の解き方を上書きしてしまった
class Dice:
    def __init__(self, input_dice):
        self.flow = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
        self.dice = [input_dice[3], input_dice[1], input_dice[0], input_dice[5], input_dice[2], input_dice[4]]
  
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.dice[0] = n0
        self.dice[1] = n1
        self.dice[2] = n2
        self.dice[3] = n3
        self.dice[4] = n4
        self.dice[5] = n5
        return self.dice
    
    def roll(self, dir):
        if dir == 'S':
            self.setNumber(self.flow[0], self.flow[2], self.flow[5], self.flow[1], self.flow[4], self.flow[3])
            self.flow = self.dice
            return self.dice
        if dir == 'N':
            self.setNumber(self.flow[0], self.flow[3], self.flow[1], self.flow[5], self.flow[4], self.flow[2])
            self.flow = self.dice
            return self.dice
        if dir == 'W':
            self.setNumber(self.flow[2], self.flow[1], self.flow[4], self.flow[0], self.flow[3], self.flow[5])
            self.flow = self.dice
            return self.dice
        if dir == 'E':
            self.setNumber(self.flow[3], self.flow[1], self.flow[0], self.flow[4], self.flow[2], self.flow[5])
            self.flow = self.dice
            return self.dice

    def identify(self, dice_x):
        self.counter = 0
        for i in range(6):
            if self.dice[i] == dice_x[i]:               
               self.counter += 1 
        if self.counter == 6:
            return True
        else:
            return False

    def check_dif(self, dice_x):
        import sys
        dice_x = [dice_x[3], dice_x[1], dice_x[0], dice_x[5], dice_x[2], dice_x[4]]
        #以下メモ書き[1,2,3,4,5,6]の入力が与えられたとする
        #以下南北方向を軸に回転させる
        #最初2が前面
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #1を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        #5を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #6を前面に持ってきて回転させる
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False:
                continue
            else:
                print('No')
                sys.exit()
        #4を前面に持ってきて回転させる
        self.roll('E')
        self.roll('S')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        #3を前面に持ってきて回転させる
        self.roll('N')
        self.roll('N')
        for i in range(4):
            self.roll('W')
            if self.identify(dice_x) == False: 
                continue
            else:
                print('No')
                sys.exit()
        return True

n = int(input())
dice = [[0] * 6 for i in range(n)]
for i in range(n):
    dice[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        d = Dice(dice[i])
        d.check_dif(dice[j])
print('Yes') 
        


Measured memory_bytes: 5636