import Data.List
import Control.Applicative

decode :: [String] -> [(String, Int)]
decode [] = []
decode (x:xs) =
  let y = words x
  in
      (head y, read (last y)) : decode xs

sortByAlphabet :: [(String, [Int])] -> [(String, [Int])]
sortByAlphabet [] = []
sortByAlphabet (p:xs) = sortByAlphabet lt ++ [(fst p, qsort (snd p))] ++ sortByAlphabet gteq
  where lt   = [x | x <- xs, fst x <  fst p]
        gteq = [x | x <- xs, fst x >= fst p]


encode :: [(String, [Int])] -> [String]
encode [] = []
encode (x:xs) = fst x : unwords (map show (snd x)) : encode xs

grouping :: [(String, Int)] -> [(String, [Int])]
grouping [] = []
grouping (x:xs) =
  let fs = filter (\y -> fst y == fst x) xs
      sd = snd x : map snd fs
      rs = xs \\ fs
  in (fst x, sd) : grouping rs


qsort :: [Int] -> [Int]
qsort [] = []
qsort (p:xs) = qsort lt ++ [p] ++ qsort gteq
  where lt   = [x | x <- xs, x <  p]
        gteq = [x | x <- xs, x >= p]

solver :: [String] -> [String]
solver xs =
  let ys = decode xs
      gs = grouping ys
      fsort = sortByAlphabet gs
  in
      encode fsort

main :: IO()
main = do
  contents <- lines <$> getContents
  mapM_ putStrLn $ solver contents