main :: IO()
main = getContents >>= putStrLn.solve.formatIn

type Dice  = [String]
formatIn :: String -> [Dice]
formatIn = map words.tail.lines

solve :: [Dice] -> String
solve (x:xs) 
    | any (judge x) xs = "No"
    | otherwise        = "Yes"

judge :: Dice -> Dice -> Bool
judge [x1,x2,x3,x4,x5,x6] y
    | y == [x1,x2,x3,x4,x5,x6] = True
    | y == [x1,x3,x5,x2,x4,x6] = True
    | y == [x1,x5,x4,x3,x2,x6] = True
    | y == [x1,x4,x2,x5,x3,x6] = True
      
    | y == [x2,x6,x3,x4,x1,x5] = True
    | y == [x2,x3,x1,x6,x4,x5] = True
    | y == [x2,x1,x4,x3,x6,x5] = True
    | y == [x2,x4,x6,x1,x3,x5] = True
      
    | y == [x3,x1,x2,x5,x6,x4] = True
    | y == [x3,x2,x6,x1,x5,x4] = True
    | y == [x3,x6,x5,x2,x1,x4] = True
    | y == [x3,x5,x1,x6,x2,x4] = True
      
    | y == [x4,x1,x5,x2,x6,x3] = True
    | y == [x4,x2,x1,x6,x5,x3] = True
    | y == [x4,x6,x2,x5,x1,x3] = True
    | y == [x4,x5,x6,x1,x2,x3] = True
      
    | y == [x5,x1,x3,x4,x6,x2] = True
    | y == [x5,x3,x6,x1,x4,x2] = True
    | y == [x5,x6,x4,x3,x1,x2] = True
    | y == [x5,x4,x1,x6,x3,x2] = True
      
    | y == [x6,x2,x4,x3,x5,x1] = True
    | y == [x6,x3,x2,x5,x4,x1] = True
    | y == [x6,x5,x3,x4,x2,x1] = True
    | y == [x6,x4,x5,x2,x3,x1] = True
      
    | otherwise                = False