loop do
    a,l = gets.split.map(&:to_i)
    break if a == 0 && l == 0
    aa = [a]
    i = j = ij = 0
    ans = 0
    loop do
        i += 1
        s = sprintf("%06d", a)[(6-l)...6]
        a = s.split(//).sort.reverse.join.to_i - s.split(//).sort.join.to_i
        if aa.include?(a)
            j = aa.index(a)
            ij = i - j
            ans = a
            break
        end
        aa.push(a)
    end
    puts "#{j} #{ans} #{ij}"
end