import Data.List

main = do
    sn <- getLine
    ods <- getContents
    let dices = map genDice $ lines ods
    if isAllDistinct dices
        then putStrLn "Yes"
        else putStrLn "No"

type Dice = (Int, Int, Int, Int, Int, Int)

isAllDistinct :: [Dice] -> Bool
isAllDistinct [] = True
isAllDistinct [x] = True
isAllDistinct (x:xs)
  | or $ map (isIdentical x) xs = False
  | otherwise = isAllDistinct xs

genDice :: String -> Dice
genDice l = (n1,n2,n3,n4,n5,n6)
  where (n1:n2:n3:n4:n5:n6:_) = map (\x -> read x :: Int) $ words l

isIdentical :: Dice -> Dice -> Bool
isIdentical (d11,d12,d13,d14,d15,d16) (d21,d22,d23,d24,d25,d26) = isSameNums && match123 && match645 && match154 && match16 && match25 && match34
  where
    isSameNums = (sort [d11,d12,d13,d14,d15,d16]) == (sort [d21,d22,d23,d24,d25,d26])
    d2 = (d21,d22,d23,d24,d25,d26)
    match123 = getRight d2 d11 d12 == Just d13
    match645 = getRight d2 d16 d14 == Just d15
    match154 = getRight d2 d11 d15 == Just d14
    match16  = getBottom d2 d11 == Just d16
    match25  = getBottom d2 d12 == Just d15
    match34  = getBottom d2 d13 == Just d14

sides :: Dice -> Int -> [Int]
sides (n1,n2,n3,n4,n5,n6) top
  | top == n1 = [n2,n3,n5,n4,n2]
  | top == n2 = [n1,n4,n6,n3,n1]
  | top == n3 = [n1,n2,n6,n5,n1]
  | top == n4 = [n1,n5,n6,n2,n1]
  | top == n5 = [n1,n3,n6,n4,n1]
  | top == n6 = [n2,n4,n5,n3,n2]
  | otherwise = sides (n1,n2,n3,n4,n5,n6) n1 -- NOT EXPECTED CASE

getRight :: Dice -> Int -> Int -> Maybe Int
getRight dice top front = next (sides dice top) front

next :: [Int] -> Int -> Maybe Int
next [x] _ = Nothing
next (x:xs) y
  | x == y    = Just (head xs)
  | otherwise = next xs y

getBottom :: Dice -> Int -> Maybe Int
getBottom (n1,n2,n3,n4,n5,n6) top
  | n1 == top = Just n6
  | n2 == top = Just n5
  | n3 == top = Just n4
  | n4 == top = Just n3
  | n5 == top = Just n2
  | n6 == top = Just n1
  | otherwise = Nothing
