import std.stdio, std.format, std.string, std.algorithm;

int[] getMaxMin( int val, int l ) {
  int[] digits = new int[]( l );
  foreach ( i; 0 .. l ) {
	digits[ i ] = val % 10;
	val /= 10;
  }
  int[] ans = new int[]( 2 );
  ans[] = 0;
  sort!"a < b"( digits );
  foreach ( i; 0 .. l ) {
	ans[ 0 ] *= 10;
	ans[ 0 ] += digits[ i ];
  }
  sort!"a > b"( digits );
  foreach ( i; 0 .. l ) {
	ans[ 1 ] *= 10;
	ans[ 1 ] += digits[ i ];
  }
  return ans;
}

int contains( int[] array, int index ) {
  foreach ( i; 0 .. index - 1 ) {
	if ( array[ index - 1 ] == array[ i ] ) {
	  return i;
	}
  }
  return -1;
}

void main()
{
  while ( true ) {
	int a, l;
	string input = readln;
	formattedRead( input, "%d %d\n", &a, &l );
	if ( a == 0 && l == 0 ) break;
	int index = 0;
	int[] array = new int[ 30 ];
	array[ index++ ] = a;
	do {
	  int[] ans = getMaxMin( a, l );
	  // stderr.writeln( ans );
	  a = array[ index++ ] = ans[ 1 ] - ans[ 0 ];
	} while ( contains( array, index ) == -1 );
	int j = contains( array, index );
	writefln( "%d %d %d", j, array[ j ], index - 1 - j );
  }
}