while true do
  a,l = gets.split.map{|s|s.to_i}
  if [a,l] == [0,0] then exit! end
  a = [a]
  while true do
    v = a.last.to_s.rjust(l,'0').chars.sort.join
    min = v.to_i
    max = v.reverse.to_i
    r = max - min
    i = a.index(r)
    if i != nil
      puts [i, r, a.length-i].join(' ')
      break
    end
    a << r
  end
end