#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
int c1(const void *v1,const void *v2){
    return strcmp((char *)v2,(char *)v1);
}
int c2(const void *v1,const void *v2){
    return strcmp((char *)v1,(char *)v2);
}
int central(int number){
    char line[8],line1[8];
    int large,small,i;
    int n1=sprintf(line,"%d",number);
    int n2=sprintf(line1,"%d",number);
    qsort(line,n1,sizeof(char),c1);
    qsort(line1,n2,sizeof(char),c2);
    for(i=n2;i<n;i++)
        line[i]=48;
    line[i]=0;
    large=atoi(line);
    small=atoi(line1);
    return large-small;
}
int main(void){
    int sign,number,max,line[21]={0},i;
    for(;max=1,sign=0,memset(line,0,sizeof(line)),scanf("%d %d",&number,&n),line[0]=number,n;){
        while(1){
            number=central(number);
            for(i=0;i<max;i++)
                if(line[i]== number){
                    printf("%d %d %d\n",i,number,max-i);
                    sign=1;
                    break;
                }
            if(sign==1)
                break;
            else{
                line[i]=number;
                max++;
            }
        }
    }
    return 0;
}