loop do
    a, l = gets.split.map(&:to_i)
    break if a == 0 && l == 0
    i = 0
    hash = {a => 0}
    loop do
        i += 1
        ary = sprintf("%0#{l}d", a).split("").sort
        a = ary.reverse.join.to_i - ary.join.to_i
        if j = hash[a]
            puts [j, a, i - j] * ' '
            break
        end
        hash[a] = i
    end
end