while true
  a = []
  a[0], l = gets.split.map(&:to_i)
  break if l == 0
  a[0] = "%0#{l}d" % a[0]
  (1..25).each do |i|
    a[i] = "%0#{l}d"  % (a[i-1].split(//).sort.reverse.join.to_i - a[i-1].split(//).sort.join.to_i)
    if a.index(a[i]) < i
      puts "#{a.index(a[i])} #{a[i]} #{i - a.index(a[i])}"
      break
    end
  end
end