object Main {
  def solve(s: String, l: Int): List[Int] = {
    val visited = Array.fill[Int](scala.math.pow(10, l).toInt)(-1)
    var dif = s.toInt
    var c = 0
    while(visited(dif) == -1) {
      visited(dif) = c
      val min = dif.toString.padTo(l, '0').split("").sortWith((a, b) => a < b)
      dif = min.reverse.mkString("").toInt - min.mkString("").toInt
      c += 1
    }
    List(visited(dif), dif, c - visited(dif))
  }
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in) 
    var s = sc.next
    var l = sc.nextInt
    while(l != 0) {
      println(solve(s, l).mkString(" "))
      s = sc.next
      l = sc.nextInt
    }
  }
}