import Control.Applicative
import Control.Monad
import Data.Function
import Data.List

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

topd :: Dice -> Int
topd (a, _, _, _, _, _) = a

frontd :: Dice -> Int
frontd (_, b, _, _, _, _) = b

rightd :: Dice -> Int
rightd (_, _, c, _, _, _) = c

spinl :: Dice -> Dice
spinl (a, b, c, d, e, f) = (a, d, b, e, c, f)

spinr :: Dice -> Dice
spinr (a, b, c, d, e, f) = (a, c, e, b, d, f)

moven :: Dice -> Dice
moven (a, b, c, d, e, f) = (b, f, c, d, a, e)

moves :: Dice -> Dice
moves (a, b, c, d, e, f) = (e, a, c, d, f, b)

movee :: Dice -> Dice
movee (a, b, c, d, e, f) = (d, b, a, f, e, c)

movew :: Dice -> Dice
movew (a, b, c, d, e, f) = (c, b, f, a, e, d)

move :: Char -> Dice -> Dice
move 'N' = moven
move 'S' = moves
move 'E' = movee
move 'W' = movew

allMoves :: Dice -> [Dice]
allMoves d = concatMap spins $ map ($d) [id, moven, moves, movee, movew, moven . moven]
  where
    spins x = [x, spinl x, spinr x, spinl (spinl x)]

normalize :: Dice -> Dice
normalize = minimum . allMoves

makeDice [a, b, c, d, e, f] = (a, b, c, d, e, f)

main = do
    n <- readLn
    dices <- replicateM n (normalize . makeDice . map read . words <$> getLine)
    putStrLn $ if (length . group . sort) dices == n then "Yes" else "No"

