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

#define INF 1000000000

void seikei(char *a, char *b) //aの先頭にある0を削除してbにcopy
{
    int i;
    int n = strlen(a);
    int p = 0;
    for (i = 0; i < n; i++)
    {
        if (a[i] != '0')
        {
            p = i;
            break;
        }
    }
    strncpy(b, a + p, n - p);
    b[n - p] = '\0';
}

void Lplus(char *a, char *b, int L)
{
    strcpy(b, a);
    int add = L - (int)strlen(a);
    int i;
    for (i = 0; i < add; i++)
    {
        strcat(b, "0");
    }
}

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

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

int main(void)
{
    char a[100];
    int L;
    while (scanf("%s %d", a, &L) != EOF)
    {
        if (strcmp(a, "0") == 0 && L == 0)
        {
            return 0;
        }
        int record[1 << 10];
        int i = 1;
        record[0] = atoi(a);
        int ans_i, ans_j;
        int ans;
        int status = 0;
        while (1)
        {
            if (status != 0)
            {
                break;
            }
            char big[100];
            char tmp[100];
            char small[100];
            Lplus(a, big, L);
            Lplus(a, tmp, L);
            qsort(big, L, sizeof(char), koujyun);
            qsort(tmp, L, sizeof(char), syojyun);
            seikei(tmp, small);
            // printf("big:%s\n", big);
            // printf("small:%s\n", small);
            record[i] = atoi(big) - atoi(small);

            sprintf(a, "%d", record[i]);

            int j, k;
            for (j = 0; j <= i; j++)
            {
                for (k = j + 1; k <= i; k++)
                {
                    if (record[j] == record[k])
                    {
                        ans = record[j];
                        ans_j = j;
                        ans_i = k;
                        status = 1;
                    }
                }
            }
            i++;
        }
        printf("%d %d %d\n", ans_j, ans, ans_i - ans_j);
    }
    return 0;
}
