import Control.Applicative ((<$>))
import Control.Monad (replicateM)

main :: IO ()
main = do
    n <- readLn
    ds <- replicateM n $ readDice <$> getLine
    putStrLn $ if solve ds then "Yes" else "No"

solve :: [Dice] -> Bool
solve (d:ds) = foldl (\acc d' -> acc && not (judge d d')) True ds

judge :: Dice -> Dice -> Bool
judge d1 d2 =  d1' == d2'
            || d1' == fmap rot d2'
            || d1' == fmap (rot.rot) d2'
            || d1' == fmap (rot.rot.rot) d2'
    where
        d1' = Just d1
        d2' = matchTB (top d1, bottom d1) d2

matchTB :: (String,String) -> Dice -> Maybe Dice
matchTB p d@(Dice t s e w n b)
    | p == (t,b) = Just d
    | p == (b,t) = Just $ goN $ goN d
    | p == (s,n) = Just $ goN d
    | p == (n,s) = Just $ goS d
    | p == (e,w) = Just $ goW d
    | p == (w,e) = Just $ goE d
    | otherwise = Nothing

goE :: Dice -> Dice
goE (Dice t s e w n b) = Dice w s t b n e
goN :: Dice -> Dice
goN (Dice t s e w n b) = Dice s b e w t n
goS :: Dice -> Dice
goS (Dice t s e w n b) = Dice n t e w b s
goW :: Dice -> Dice
goW (Dice t s e w n b) = Dice e s b t n w

rot :: Dice -> Dice
rot (Dice t s e w n b) = Dice t w s n e b

data Dice = Dice
    { top :: String
    , south :: String
    , east :: String
    , west :: String
    , north :: String
    , bottom :: String
    } deriving (Eq)

readDice :: String -> Dice
readDice str = Dice t s e w n b
    where (t:s:e:w:n:b:_) = words str