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

int main(void){
	int l,i,j,a[6],count;
	long n,tmp,max,min,b[20],f=0;
	
	scanf("%ld %d",&n,&l);
	
	while(1){
		
		if(n==0 && l==0)break;
		
		max=0;
		min=0;
		tmp=0;
		count=0;
		f=0;
		for(i=0;i<20;i++){
			b[i]=0;
		}
		
		for(i=0;i<l;i++){
			a[i]=0;
		}
		
		
		while(f!=1){
			
			max=0;
			min=0;
			
			//if(f==1)break;
			
			if(count==0){
				b[count]=n;
			}else{
			
			for(i=0;i<count;i++){
				if(n==b[i] || i>=19){
					
					printf("%d %ld %d\n",i,b[i],count-i);
					
					f=1;
					break;
				}
				
			}
			}
		
		for(i=0;i<l;i++){
			a[i]=n%10;
			n=n/10;
			//if(max<a[i]) max=a[i];
			//if(min>a[i]) min=a[i];
			
			//fprintf(fout,"%d\n",a[i]);
		}
		
		for(i=0;i<l-1;i++){
			for(j=i+1;j<l;j++){
				if(a[i]<a[j]){
					tmp=a[i];
					a[i]=a[j];
					a[j]=tmp;
				}
			}
		}
		
		for(i=0;i<l;i++){
			max+=a[i]*pow(10,(l-i-1));
			min+=a[i]*pow(10,i);
		}
		
		count++;
		
		n=max-min;
		
		b[count]=n;
		
		//fprintf(fout,"max=%ld, min=%ld\n",max,min);
		
		}
		
		scanf("%ld %d",&n,&l);
	}

	return 0;
}