import Data.Char import Data.List import Data.Monoid main :: IO () main = getLine >> getLine >>= putStrLn . unwords . solve . words solve :: [String] -> [String] solve = sortBy compf compf :: String -> String -> Ordering compf (x : xs) (y : ys) | x `elem` "CD" && y `elem` "CD" = compare (ord y) (ord x) `mappend` compare (read' xs) (read' ys) | otherwise = compare (ord x) (ord y) `mappend` compare (read' xs) (read' ys) compf _ _ = error "compf" read' :: String -> Int read' x | x == "A" = 1 | x == "T" = 10 | x == "J" = 11 | x == "Q" = 12 | x == "K" = 13 | otherwise = read x