import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._
  solve
  @tailrec def solve: Unit = {
    val Array(a, l) = readLine.trim.split(' ').map(_.toInt)
    if (l == 0) return
    var single = a
    var double = next(a, l)
    while (single != double){
      single = next(single, l)
      double = next(next(double, l), l)
    }
    var count = 1
    double = next(single, l)
    while(single != double){
      count += 1
      double = next(double, l)
    }
    double = a
    for (_ ← 0 until count){
      double = next(double, l)
    }
    var j = 0
    single = a
    while(single != double){
      j += 1
      single = next(single, l)
      double = next(double, l)
    }
    println(s"$j $single $count")
    solve
  }
  def next(number: Int, length: Int): Int = {
    val list = number.toList(length)
    list.sorted(Ordering[Int].reverse).toInt - list.sorted.toInt
  }
  implicit class ImplicitIntToList(private val number: Int) {
    def toList(length:Int): List[Int] = {
      toList(length, number)
    }
    private def toList(length: Int, number: Int, result: List[Int] = Nil): List[Int] = {
      length match{
        case 0 ⇒ result
        case _ ⇒ toList(length - 1, number / 10, number % 10 ::result)
      }
    }
  }
  implicit class ImplicitListToInt(private val list:List[Int]) {
    def toInt: Int = list.foldLeft(0){case (i, n) ⇒ i * 10 + n}
  }
}

