module Main where
-- import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Data.Functor
import Control.Monad

rollData :: [(Int, [[(Int, Int)]])]
rollData =
        [
            (0, []),                                -- e
            (3,[
                [(0, 2), (2, 5), (3, 0), (5, 3)],      -- x
                [(0, 4), (1, 0), (4, 5), (5, 1)],      -- y
                [(1, 3), (2, 1), (3, 4), (4, 2)]]),    -- z
            (2,[
                [(0, 3), (1, 5), (2, 1), (3, 4), (4, 0), (5, 2)],  -- d1
                [(0, 1), (1, 3), (2, 5), (3, 0), (4, 2), (5, 4)],  -- d2
                [(0, 2), (1, 0), (2, 1), (3, 4), (4, 5), (5, 3)],  -- d3
                [(0, 4), (1, 3), (2, 0), (3, 5), (4, 2), (5, 1)]]), -- d4
            (1,[
                [(0, 1), (1, 0), (2, 3), (3, 3), (4, 5), (5, 4)],  -- p1 
                [(0, 2), (1, 4), (2, 0), (3, 5), (4, 1), (5, 3)],  -- p2 
                [(0, 4), (1, 5), (2, 3), (3, 2), (4, 0), (5, 1)],  -- p3 
                [(0, 3), (1, 4), (2, 5), (3, 0), (4, 1), (5, 2)],  -- p4 
                [(0, 5), (1, 2), (2, 1), (3, 4), (4, 3), (5, 0)],  -- p5 
                [(0, 5), (1, 3), (2, 4), (3, 1), (4, 2), (5, 0)]])  -- p6 
        ]

solve :: [[Int]] -> String
solve l = if any (\[x, y] -> eq x y) (comb l 2) then "No" else "Yes" 

eq :: [Int] -> [Int] -> Bool
eq d1 d2 = -- trace ("tr0 d1:"++show d1++" d2:"++show d2) $
            any (\(n, rs) -> checkRolls n rs) rollData where
    checkRolls 0 [] = d1 == d2
    checkRolls _ [] = False
    checkRolls n (m:ms) = -- trace ("tr1 n:"++show n++" m:"++show m++" ms:"++show ms) $ 
                          if checkRoll n m dice then True else checkRolls n ms where
        checkRoll 0 _ _ = False
        checkRoll n m d = -- trace ("tr2 n:"++show n++" m:"++show m++" d:"++show d++" r:"++show rolled) $ 
                          if checkFaces rolled then True else checkRoll (n-1) m rolled where
            checkFaces d = iter [0..5] d1 where
                iter [] [] = True
                iter (i:xs) (j:ys) 
                    | d!i == j = iter xs ys
                    | otherwise = False
            rolled = roll [] m where
                roll ac [] = d // ac
                roll ac ((i, j):xs) = roll ((i, d!j):ac) xs
        dice = listArray (0, 5) d2

comb :: [a] -> Int-> [[a]]
comb _ 0 = [[]]
comb [] _ = []
comb (x:xs) r = map (x:) (comb xs (r-1)) ++ comb xs r 

readLine:: IO [Int]
readLine = map read . words <$> getLine

main :: IO() 
main = do
    n  <- readLn
    l <- replicateM n readLine
--    print l
    putStrLn (solve l)

