while true
	a,l = gets.split(" ").map{|e|e.to_i}
	break if a==0 && l==0

	array=[a]
	while true
		small=array[-1].to_s.split("").sort.join.to_i
		big=small.to_s.reverse
		(l-big.length).times{big+="0"}
		big = big.to_i
		now = big - small
		if array.index(now) == nil
			array.push big-small
		else
			puts "#{array.index(now)} #{now} #{array.length - array.index(now)}"
			break
		end
	end

end