data Suit = S|H|C|D deriving (Eq,Ord,Show,Read)

data Trump = Trump Suit Int deriving (Eq)

instance Show Trump where
	show (Trump suit rank) = (show suit) ++ " " ++ (show rank)

instance Ord Trump where
	(>) (Trump a x) (Trump b y)
	 |a==b = x>y
	 |otherwise = a>b
	(<) (Trump a x) (Trump b y)
	 |a==b = x<y
	 |otherwise = a<b
	(<=) (Trump a x) (Trump b y)
	 |a==b = x<=y
	 |otherwise = a<=b
	(>=) (Trump a x) (Trump b y)
	 |a==b = x>=y
	 |otherwise = a>=b
	 

readTrump :: String->Trump
readTrump xs = Trump (read (head xs:[]) :: Suit) (read (tail xs) :: Int)

quickSort :: (Ord a) => [a]->[a]
quickSort [] = []
quickSort xs = (smallerOrEqual xs) ++ [head xs] ++ (larger xs)
	where
	smallerOrEqual xs = quickSort $ filter (<= head xs) (tail xs)
	larger xs = quickSort $ filter (> head xs) xs
	
trumpComp :: [Trump]->[Trump]->[Trump]
trumpComp x [] = x
trumpComp (x:xs) yys@(y:ys)
	|x==y = trumpComp xs ys
	|x/=y = x : trumpComp xs yys

trumpList :: [Trump]
trumpList = [Trump x y|x<-[S,H,C,D],y<-[1..13]]

filterTrump :: [Trump]->[Trump]
filterTrump = trumpComp trumpList

main = getContents >>= putStrLn.unlines.map show.filterTrump.quickSort.map readTrump.tail.lines