Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice IV

Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III.

Input

In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III.

Output

Print "Yes" if given dices are all different, otherwise "No" in a line.

Constraints

$2 \leq n \leq 100$

$0 \leq $ the integer assigned to a face $ \leq 100$

Sample Input 1

3
1 2 3 4 5 6
6 2 4 3 5 1
6 5 4 3 2 1

Sample Output 1

No

Sample Input 2

3
1 2 3 4 5 6
6 5 4 3 2 1
5 4 3 2 1 6

Sample Output 2

Yes

Solution in Python3 (judge verdict: Wrong Answer)

class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east

q = int(input())
dice1 = Dice(list(map(int,input().split())))
for i in range(q-1):
    dice2 = Dice(list(map(int,input().split())))
    h=""

    for i in range(4):
        dice2.rotate_west()
        if dice1.top == dice2.top:
            for _ in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = "Yes"
    for _ in range(4):
        dice2.rotate_north()
        if dice1.top == dice2.top:
            for m in range(4):
                dice2.rotate_horizon()
                if dice1.south == dice2.south:
                    if dice1.east == dice2.east and dice1.west == dice2.west:
                        h = "Yes"
    if h:
        continue
    else:
        h="No"
        break
print(h)