object Main extends App {
  val src: List[(String, Array[Int])] = io.Source.stdin.getLines.toList.map(_.split(" ")).map { case Array(a, b) => (a, Array(b)) }.sortWith(_._1 < _._1).map( tup => (tup._1, tup._2.map(_.toInt)))

  def step(li: List[(String, Array[Int])], tup: (String, Array[Int])): List[(String, Array[Int])] = li match {
    case Nil => List(tup)
    case h :: tail if h._1 == tup._1 => (h._1, h._2 :+ tup._2(0)) :: tail
    case h :: tail => h :: step(tail, tup)
  }

  val mergeNum: List[(String, Array[Int])] = (Nil /:[List[(String, Array[Int])]] src)(step)

  mergeNum.map { case (str, arr) => println(s"${str}\n${arr.sorted.mkString(" ")}")}
}

