#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
int comp(const void *a, const void *b){//昇順
    int c = *(int *)a;
    int d = *(int *)b;
    if(c<d) return -1;
    else return 1;
}
int comp2(const void *a, const void *b){//降順
    int c = *(int *)a;
    int d = *(int *)b;
    if(c<d) return 1;
    else return -1;
}
int arraytonum(int x[], int L){
    int ans=0;
    for(int i=0; i<L; i++){
        ans+=x[i];
        ans*=10;
    }
    return ans/10;
}
void cal(int a0, int L){
    int work[L];
    int array[21];
    int count=0;
    while(1){
        array[count]=a0;
        for(int i=L-1; i>=0; i--){
            work[i]=a0%10;
            a0/=10;
        }
        //rep(i,L) printf("%d",work[i]); puts("");
        qsort(work,L,sizeof(int),comp2);
        //rep(i,L) printf("%d",work[i]); puts("");
        int ai=arraytonum(work,L);
        qsort(work,L,sizeof(int),comp);
        int aj=arraytonum(work,L);
        a0=ai-aj;
        //printf("a0=%d\n",a0);
        for(int j=0;j<count;j++){
            if(array[count]==array[j]){
                printf("%d %d %d\n",j,array[count],count-j);
                return;
            }
        }
        count++;
    }
    return;
}
int main(void){
    int a0, L;
    while(1){
        scanf("%d%d", &a0, &L);
        if(a0==0 && L==0) break;
        cal(a0,L);
    }
}
