#11_A
import random
class Dice:
    def __init__(self, numbers):
        self.dice=[i for i in numbers]
        self.workspace=[i for i in numbers]
        
        self.top=self.dice[0]
        
        
    def rotate(self,command):
        if command == "W":
            self.workspace=[self.dice[2], self.dice[1], self.dice[5], self.dice[0], self.dice[4], self.dice[3]]
            self.dice=self.workspace
        elif command == "E":
            self.workspace=[self.dice[3], self.dice[1], self.dice[0], self.dice[5], self.dice[4], self.dice[2]]
            self.dice = self.workspace
        
        if command == "S":
            self.workspace=[self.dice[4], self.dice[0], self.dice[2], self.dice[3], self.dice[5], self.dice[1]]
            self.dice=self.workspace
        elif command == "N":
            self.workspace=[self.dice[1], self.dice[5], self.dice[2], self.dice[3], self.dice[0], self.dice[4]]
            self.dice=self.workspace
            
    def get_top(self):
        self.top=self.dice[0]
        print(self.top)
        
    def predict(self, num):
        for i in range(num):
            top, front = map(int, input().split())
            while(True):
                if top == self.dice[0] and front == self.dice[1]:
                    break
                command_num=random.randint(1,4)
                if command_num == 1:
                    self.rotate("W")
                elif command_num == 2:
                    self.rotate("E")
                elif command_num == 3:
                    self.rotate("S")
                elif command_num == 4:
                    self.rotate("N")
            print(self.dice[2])
            
    def getter(self):
        return self.dice[0], self.dice[1], self.dice[2], self.dice[3], self.dice[4], self.dice[5]
    
    def predict_same(self, top, front, right, left, back, bottom):
        for n in range(300):
            if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
                break
            command_num=random.randint(1,4)
            if command_num == 1:
                    self.rotate("W")
            elif command_num == 2:
                    self.rotate("E")
            elif command_num == 3:
                    self.rotate("S")
            elif command_num == 4:
                    self.rotate("N")
        
        if top ==self.dice[0] and front== self.dice[1] and right ==self.dice[2]:
            if self.dice[3] == left and self.dice[4] == back and self.dice[5] == bottom:
                return "Yes"
                
            else:
                return "No"
                
        else:
            return "No"
            
        
            
                
    









q=int(input())
list_dice=[]
judges=[]
# list_numbers=[[0 for i in range(6)]  for i in range(q)]
for i in range(q):
    numbers=list(map(int, input().split()))
    dice=Dice(numbers)
    list_dice.append(dice)
i=0
while(True):
    if (i+1) == len(list_dice):
        break
    for n in range(i+1,len(list_dice)):
        top, front, right, left, back, bottom=list_dice[i].getter()
        judges.append(list_dice[n].predict_same(top, front, right, left, back, bottom)) 
    i+=1
    
if "Yes" in judges:
    print("No")
else:
    print("Yes")

    


Measured memory_bytes: 8292