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

int a[20];
int L;


int comp1(const void* p1, const void* p2){//??????
	char* c1=(char*)p1;
	char* c2=(char*)p2;
	return *c1-*c2;
}
int comp2(const void* p1, const void* p2){//??????
	char* c1=(char*)p1;
	char* c2=(char*)p2;
	return *c2-*c1;
}

int next(int a){
	char str[7];
	sprintf(str,"%06d",a);
	qsort(str,6,sizeof(char),comp1);
	int small=atoi(&str[6-L]);
	qsort(str,6,sizeof(char),comp2);
	str[L]=0;
	int large=atoi(&str[0]);
	return large-small;
}

void solve(){
	int i,j;
	for(i=1;i<20;i++){
		a[i]=next(a[i-1]);
	}
	for(i=1;i<20;i++){
		for(j=0;j<i;j++){
			if(a[i]==a[j]){
				printf("%d %d %d\n",j,a[i],i-j);
				return;
			}
		}
	}
}

int main(void){
	
	while(scanf("%d %d",&a[0],&L),L){
		solve();
	}

	return 0;
}