import Data.List

parse :: String -> (String , Int)
parse xs = let [s , i] = words xs in (s , read i)

output :: [(String , Int)] -> IO ()
output xs = putStrLn (fst $ head xs) >> (putStrLn $ unwords $ map (show . snd) xs)

main :: IO ()
main = getContents
    >>= return . map parse . lines
    >>= return . groupBy (\ x y -> fst x == fst y) . sort
    >>= mapM_ output