import           Data.List

longest :: [[a]] -> [a]
longest = maximumBy (\a b -> compare (length a) (length b))

mrw :: String -> String
mrw = head . longest . group . sort . words

mlw :: String -> String
mlw = longest . words

main :: IO ()
main = getContents >>= mapM_ f . lines
  where f s = putStrLn $ mrw s ++ " " ++ mlw s