#include <stdio.h>

int getNextNumber(int n,int L) {
	char format[100];
	char buffer[100];
	int max,min;
	int i,j;
	char temp;
	sprintf(format,"%%0%dd",L);
	sprintf(buffer,format,n);
	for(i=L-1;i>0;i--) {
		for(j=0;j<i;j++) {
			if(buffer[j]<buffer[j+1]) {
				temp=buffer[j];
				buffer[j]=buffer[j+1];
				buffer[j+1]=temp;
			}
		}
	}
	sscanf(buffer,"%d",&max);
	for(i=0;i+i<L;i++) {
		temp=buffer[i];
		buffer[i]=buffer[L-i-1];
		buffer[L-i-1]=temp;
	}
	sscanf(buffer,"%d",&min);
	return max-min;
}

int main(void) {
	int a,L;
	int numbers[21];
	int i,j,found;
	while(scanf("%d%d",&a,&L)==2 && (a|L)!=0) {
		numbers[0]=a;
		for(i=1;i<21;i++)numbers[i]=getNextNumber(numbers[i-1],L);
		for(i=1;i<21;i++) {
			found=0;
			for(j=0;j<i;j++) {
				if(numbers[i]==numbers[j]) {
					found=1;
					break;
				}
			}
			if(found)break;
		}
		if(i>=21)return 1;
		printf("%d %d %d\n",j,numbers[j],i-j);
	}
	return 0;
}