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

int comp_as( const void *, const void * );
int comp_des( const void *, const void * );

int main( void ) {
	char aStr[ 20 ][ 7 ], min[ 7 ], max[ 7 ];
	int i, j, a0, L;

	for ( ; scanf( "%d %d", &a0, &L ), L; printf( "%d %d %d\n", j, atoi( aStr[ i ] ), i - j ) ) {
		sprintf( aStr[ 0 ], "%0*d", L, a0 );

		for ( i = 1; ; i++ ) {
			strcpy( min, aStr[ i - 1 ] );
			qsort( min, L, sizeof(char), &comp_as );

			strcpy( max, aStr[ i - 1 ] );
			qsort( max, L, sizeof(char), &comp_des );

			sprintf( aStr[ i ], "%0*d", L, atoi( max ) - atoi( min ) );

			for ( j = 0; j < i; j++ )
				if ( !strcmp( aStr[ j ], aStr[ i ] ) )
					break;
			if ( j < i )
				break;
		}
	}

	return 0;
}

int comp_as( const void *a, const void *b ) {
	return *(char *)a - *(char *)b;
}

int comp_des( const void *a, const void *b ) {
	return *(char *)b - *(char *)a;
}