import Control.Applicative

type Dice    = [(Int, Int)]
type Command = Char

fromList :: [Int] -> Dice
fromList [a, b, c, d, e, f] = [(a, f), (b, e), (c, d)]
fromList _ = error "Invalid dice."

rev :: (a,a) -> (a,a)
rev (x,y) = (y,x)

roll :: Dice -> Command -> Dice
roll [a, b, c] com =
    case com of
        'N' -> [b, rev a, c]
        'E' -> [rev c, b, a]
        'S' -> [rev b, a, c]
        'W' -> [c, b, rev a]
        _   -> error "Invalid command."
roll _ _ = error "Invalid command."

spin :: Dice -> [Dice]
spin [a, b, c] = [ [a, b, c]
                 , [a, rev c, b]
                 , [a, rev b, rev c]
                 , [a, c, rev b]
                 ]
spin _ = error "Invalid dice."

dicePermutation :: Dice -> [Dice]
dicePermutation d = spin d ++ spin d' ++ concatMap (spin  . roll d) "NEWS"
  where d' = roll (roll d 'N') 'N'

equalDices :: [Dice] -> Bool
equalDices []     = True
equalDices (x:xs) = all (`notElem` dicePermutation x) xs && equalDices xs

main :: IO ()
main = do
    dices <- map (fromList . map read . words) . tail . lines <$> getContents
    putStrLn $ if equalDices dices then "Yes" else "No"