
object Main extends App {

  override def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    Iterator.continually(new Data(sc.nextInt, sc.nextInt))
      .takeWhile(_.continue).map(_.solve).foreach(d => println(d._1+" "+ d._2+" "+ d._3));
  }

  case class Data(a0: Int, i: Int) {
    val continue = !(a0 == 0 && i == 0)

    def solve: (Int, Int, Int) = {
      val arr = (1 to 21).scanLeft(a0)((z, n) => getNext(z)).toArray
      val map = scala.collection.mutable.Map.empty[Int, Int]
      val list = for (i <- (0 until arr.length); j <- (i + 1 until arr.length)) yield (arr(i) - arr(j), (i, arr(i), j - i))
      list.find(_._1 == 0).get._2
    }

    def getNext(seed: Int): Int = {
      val (max, min) = maxmin(seed)
      max - min
    }

    def maxmin(seed: Int): (Int, Int) = {
      val list = (1 to i-1).scanLeft(seed)((z, n) => z / 10).map(_ % 10).sorted
      val min = list.reduceLeft((z, n) => z * 10 + n)
      val max = list.reduceRight((n, z) => z * 10 + n)
      (max, min)
    }
  }
}