import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

data Dice = Dice [Int] deriving (Show, Eq)

rollDice :: Char -> Dice -> Dice
rollDice 'N' (Dice [a,b,c,d,e,f]) = Dice [b,f,c,d,a,e]
rollDice 'E' (Dice [a,b,c,d,e,f]) = Dice [d,b,a,f,e,c]
rollDice 'S' d = foldr1 (.) (replicate 3 $ rollDice 'N') $ d
rollDice 'W' d = foldr1 (.) (replicate 3 $ rollDice 'E') $ d

topDice :: Dice -> Int
topDice (Dice (a:_)) = a

question' :: Dice -> Dice -> Bool
question' d e = not $ null setFront
  where
    setTop = filter ((==(topDice e)) . topDice) ([d] ++ [rollDice 'N' . rollDice 'N' $ d] ++ map (flip rollDice d) "NESW")
    setFront = setTop >>= \f -> filter (==(rollDice 'E' e)) (scanr rollDice (rollDice 'E' f) "NNN")
    
question :: [Dice] -> Bool
question [] = True
question (d:ds) = all (not . question' d) ds && question ds

main = do
  n <- readLn
  ds <- map (Dice . map read . words) <$> replicateM n getLine
  putStrLn $ if question ds then "Yes" else "No"
  