import Data.List

n :: [Int] -> [Int]
n [a,b,c,d,e,f] = [b,f,c,d,a,e]

w :: [Int] -> [Int]
w [a,b,c,d,e,f] = [c,b,f,a,e,d]

turn :: [Int] -> [[Int]]
turn [a,b,c,d,e,f] = [a,b,c,d,e,f] : [a,c,e,b,d,f] : [a,e,d,c,b,f] : [a,d,b,e,c,f] : []

solve :: String -> [Int] -> [[Int]]
solve [] _ = []
solve (x:xs) list
  | 'f'	== x = turn list ++ solve xs list
  | 'n' == x = (turn . n) list ++ solve xs (n list)
  | 'w' == x = (turn . w) list ++ solve xs (w list)

main = do
  n <- fmap (*24) readLn
  m <- fmap (length . nub . concat . map (solve "fnnwnn". map read . words) . lines) getContents
  if n == m then putStrLn "Yes" else putStrLn "No"