#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void sort(char a[], int n)
{
    int i, j;

    for(i = 0; i < n; i++){//descending
        for(j = 1; j < n - i; j++){
            if(a[j] > a[j - 1]){
                char temp = a[j];
                a[j] = a[j - 1];
                a[j - 1] = temp;
            }
        }
    }
}

int main(void)
{
    char a[8];
    char min[8];
    char max[8];
    int num;
    int L;

    while(1){
        int i, j;
        char a_n[21][8];

        scanf("%d %d", &num, &L);

        if(num == 0 && L == 0)
            break;

        sprintf(a + 1, "%d", num);
        strcpy(&a_n[0][1], a + 1);
        i = 1;
        j = 0;
        while(1){
            int k, l;
            int index;
            int len = strlen(a + 1);

            sort(a + 1, len);

            for(k = 0; k <= L; k++){
                max[k] = min[k] = '0';
            }
            max[k] = min[k] = '\0';


            index = 1;
            for(k = 1; k <= len; k++){
                max[index++] = a[k];
            }

            index = L - len + 1;
            for(k = len; k > 0; k--){
                min[index++] = a[k];
            }


            sprintf(a + 1, "%d", atoi(max) - atoi(min));


            index = 0;//use index as a flag
            for(k = 0; k < i; k++){
                if(strcmp(a + 1, &a_n[k][1]) == 0){
                    j = k;
                    index = 1;
                }
            }

            if(index)
                break;

            strcpy(&a_n[i++][1], a + 1);
        }

        printf("%d %s %d\n", j, a + 1, i - j);
    }

    return 0;
}