import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim.toList match {
      case '#'::Nil ⇒ return
      case l ⇒
        val suspects = ('b' to 'z').foldRight(List(l)){case (target, list) ⇒ list.flatMap(makeSuspects(_, target))}.map(_.mkString("")).sorted.toArray
        println(suspects.length)
        if (suspects.length > 10) {
          suspects.take(5).foreach(println)
          suspects.takeRight(5).foreach(println)
        }else {
          suspects.foreach(println)
        }
    }
    loop()
  }
  def makeSuspects(current: List[Char], target: Char): List[List[Char]] = {
    current match {
      case `target`::_ ⇒ Nil
      case h::t if h + 1 == target ⇒ (target::t)::makeSuspects(t, target).map(h::_)
      case h::t ⇒ makeSuspects(t, target).map(h::_)
      case Nil ⇒ List(Nil)
    }
  }
}
