a = []
while true
  a[0], l = gets.split.map(&:to_i)
  break if l == 0
  a[0] = "%0#{l}d" % a[0]
  catch :exit do
    for i in 1..25
      a[i] = "%0#{l}d"  % (a[i-1].split(//).sort.reverse.join.to_i - a[i-1].split(//).sort.join.to_i)
      for j in 0...i
        if a[i] == a[j]
          puts "#{j} #{a[i].to_i} #{i-j}"
          throw :exit   
        end
      end
    end
  end
end