import Data.List

toDice :: [Int] -> [[Int]]
toDice [a,b,c,d,e,f] = [[a,f],[b,e],[c,d]]

pattern1 :: [Int] -> [String]
pattern1 [a,b,_,_,e,f] = map show [a,b,f,e,a]

pattern2 :: [Int] -> [String]
pattern2 [a,_,c,d,_,f] = map show [c,a,d,f,c]

pattern3 :: [Int] -> [String]
pattern3 [_,b,c,d,e,_] = map show [b,c,e,d,b]

solve :: [Int] -> String -> Int
solve list x
  | isInfixOf x (unwords $ pattern1 list) = list !! 2
  | isInfixOf x (unwords $ pattern2 list) = list !! 1
  | isInfixOf x (unwords $ pattern3 list) = list !! 0
  | isInfixOf x (unwords $ reverse $ pattern1 list) = list !! 3
  | isInfixOf x (unwords $ reverse $ pattern2 list) = list !! 4
  | isInfixOf x (unwords $ reverse $ pattern3 list) = list !! 5
--  | otherwise = -1                                                           

check1 :: [Int] -> [Int] -> Bool
check1 xs ys = (solve' xs) == (solve' ys)
  where solve' = sort . map sort . toDice

check2 :: [Int] -> [Int] -> String -> Bool
check2 xs ys s = (solve xs s) == (solve ys s)

diff :: [Int] -> [Int] -> Bool
diff xs ys = (check1 xs ys) && (check2 xs ys (mkstr xs))
  where mkstr = unwords . map show . take 2

main = getContents >>= putStrLn . (\b -> if or b then "No" else "Yes") . (\((n:_):xs) -> [ diff (xs !! a) (xs !! b) | [a,b] <- (conbination n)]) . read' . lines
  where read' = map (map read . words)
        conbination n = nub $ map (sort . take 2) $ permutations [0..n-1]