while True:

    n, d = list(map(int, input().split()))

    if n == 0 and d == 0: break



    a = [n]

    cnt = 0

    while True:

        t = list(map(int, list(("{:0%d}"%d).format(n))))

        n = int("".join(map(str, sorted(t, reverse=True)))) - int("".join(map(str, sorted(t))))

        if n in a:

            break

        a.append(n)

        cnt += 1

    i = a.index(n)

    print((i, n, cnt - i + 1))
def solve(n, l):

    results = [n]

    for i in range(20):

        s = list(("%0" + str(l) + "d") % n)

        s.sort()

        n = int("".join(s[::-1])) - int("".join(s))

        if n in results:

            break

        results.append(n)

    j = results.index(n)

    print((j, n, i - j + 1))



while True:

    n, l = list(map(int, input().split()))

    if n == l == 0:

        break

    solve(n, l)



while True:
    n, d = list(map(int, input().split()))
    if n == 0 and d == 0:
        break
    a = [n]
    cnt = 0
    while True:
        t = list(map(int, list(("{:0%d}" % d).format(n))))
        n = int("".join(map(str, sorted(t, reverse=True)))) - int(
            "".join(map(str, sorted(t)))
        )
        if n in a:
            break
        a.append(n)
        cnt += 1
    i = a.index(n)
    print((i, n, cnt - i + 1))

def solve(n, l):
    results = [n]
    for i in range(20):
        s = list(("%0" + str(l) + "d") % n)
        s.sort()
        n = int("".join(s[::-1])) - int("".join(s))
        if n in results:
            break
        results.append(n)
    j = results.index(n)
    print((j, n, i - j + 1))


while True:
    n, l = list(map(int, input().split()))
    if n == l == 0:
        break
    solve(n, l)

+def solve(n, l): +    results = [n] +    for i in range(20): +        s = list(("%0" + str(l) + "d") % n) +        s.sort() +        n = int("".join(s[::-1])) - int("".join(s)) +        if n in results: +            break +        results.append(n) +    j = results.index(n) +    print((j, n, i - j + 1)) + + -    n, d = list(map(int, input().split())) -    if n == 0 and d == 0: +    n, l = list(map(int, input().split())) +    if n == l == 0: -    a = [n] -    cnt = 0 -    while True: -        t = list(map(int, list(("{:0%d}" % d).format(n)))) -        n = int("".join(map(str, sorted(t, reverse=True)))) - int( -            "".join(map(str, sorted(t))) -        ) -        if n in a: -            break -        a.append(n) -        cnt += 1 -    i = a.index(n) -    print((i, n, cnt - i + 1)) +    solve(n, l)