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

void iSortAscend( char *, int );
void iSortDescend( char *, int );

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

	while ( scanf( "%d %d", a, &L ), L ) {
		sprintf( aStr[ 0 ], "%0*d", L, a[ 0 ] );

		for ( i = 1; ; i++ ) {
			strcpy( min, aStr[ i - 1 ] );
			iSortAscend( min, L );

			strcpy( max, aStr[ i - 1 ] );
			iSortDescend( max, L );

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

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

		printf( "%d %d %d\n", j, a[ i ], i - j );
	}

	return 0;
}


void iSortAscend( char *data, int n ) {
	char tmp;
	int i, j;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ] > tmp ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];
				j--;
			} while ( j > 0 && data[ j - 1 ] > tmp );
			data[ j ] = tmp;
		}
	}
}

void iSortDescend( char *data, int n ) {
	char tmp;
	int i, j;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		if ( data[ i - 1 ] < tmp ) {
			j = i;
			do {
				data[ j ] = data[ j - 1 ];
				j--;
			} while ( j > 0 && data[ j - 1 ] < tmp );
			data[ j ] = tmp;
		}
	}
}