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

type Dice = [Int]

leq :: Dice -> Dice -> Bool
leq [] [] = True
leq (x:xs) (y:ys)
    | x < y = True
    | x > y = False
    | otherwise = leq xs ys

minDice:: Dice -> Dice -> Dice
minDice d1 d2
    | leq d1 d2 = d1
    | otherwise = d2

rotate:: Dice -> Char -> Dice
rotate [u,f,r,l,b,d] 'E' = [l,f,u,d,b,r]
rotate [u,f,r,l,b,d] 'N' = [f,d,r,l,u,b]
rotate [u,f,r,l,b,d] 'S' = [b,u,r,l,d,f]
rotate [u,f,r,l,b,d] 'W' = [r,f,d,u,b,l]
rotate xs _              = xs

search :: [Dice]->[Dice]->Dice
search dices searched
  | null dices =  foldl1 minDice searched
  | otherwise = search next (searched ++ dices)
  where
    next = filter (`notElem` searched) [rotate d opt | d <-dices, opt<-"ENSW" ]

main :: IO ()
main = do
  num <- getLine
  dices <- replicateM (read num) (map (read::String->Int) . words <$> getLine)
  let ds = [search [d] [] | d <-dices]
  putStrLn $ if length ds == length (nub ds) then "Yes" else "No"
