### subroutines

def d2n(ds)
  sum = 0
  for d in ds
    sum = sum * 10 + d
  end
  sum
end

def next_a(ai, l)
  ds = []
  k = 0
  while ai > 0
    ds[k] = ai % 10
    ai /= 10
    k += 1
  end
  while k < l
    ds[k] = 0
    k += 1
  end

  min_d = d2n(ds.sort!)
  max_d = d2n(ds.reverse!)
  max_d - min_d
end

### main

loop do
  a0, l = gets.split.map(&:to_i)
  break if (a0 | l) == 0

  as = [a0]
  i = j = 0

  loop do
    i += 1
    as[i] = next_a(as[i - 1], l)
    j = as.index(as[i])
    break if j < i
  end

  puts [j, as[i], i - j].join(' ')
end