#include <stdio.h>
#include <stdlib.h>
#define L_MAX 6
#define I_MAX 20

int anagram(int n, int l, int (*comp)(const void*, const void*))
{
    char arr[L_MAX];
    int i;

    for(i = l - 1; i >= 0; i--, n /= 10)
        arr[i] = n % 10;

    qsort(arr, l, 1, comp);

    for(n = i = 0; i < l; i++)
        n = n * 10 + arr[i];

    return n;
}

int smallest(const void* a, const void* b) { return *(char*)a - *(char*)b; }
int largest(const void* a, const void* b) { return *(char*)b - *(char*)a; }

int main(void)
{
    int history[I_MAX], n, l, i, j;

  next:

    while(scanf("%d %d", &n, &l), n + l)
    {
        i = 0;

        while(1)
        {
            history[i] = n;

            n = anagram(n, l, largest) - anagram(n, l, smallest);
            i++;

            for(j = 0; j < i; j++)
                if(history[j] == n)
                {
                    printf("%d %d %d\n", j, n, i - j);
                    goto next;
                }
        }
    }

    return 0;
}