/*
AizuOnline A1180
Title  Recurring Decimals
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N,L;
char buf[7];
int  log_[21];
//
int comp_char(void * x,void * y)
{
  return(*(char *)x - *(char *)y);
}
int comp_char_r(void * x,void * y)
{
  return(*(char *)y - *(char *)x);
}

int rule(int a,int d)
{
  int saishou,saidai;

  sprintf(buf,"%0*d",d,a);
  qsort(buf,d,sizeof(char),comp_char_r);
  //printf("MAX:%s\n",buf);
  sscanf(buf,"%d",&saidai);
  //printf("sd:%d\n",saidai);
  qsort(buf,d,sizeof(char),comp_char);
  //printf("MIN:%s\n",buf);
  sscanf(buf,"%d",&saishou);
  //printf("ss:%d\n",saishou);
  return(saidai-saishou);
}
int chkloop(int N,int Len)
{
  int i;

  for(i=0;i<Len;i++)
    if(N==log_[i])
      return(i);
  return(-1);
}
main()
{
  int i,ret;

  while(EOF!=scanf("%d %d",&N,&L) && (N || L))
    {
      log_[0]=N;
      for(i=0;i<20;i++)
	{
	  N=rule(N,L);
	  log_[i+1]=N;
	  ret=chkloop(N,i+1);
	  //printf("r=%d:",ret);
	  if(ret>=0)
	    break;
      //printf("%d\n",N);
	}
      printf("%d %d %d\n",ret,N,i-ret+1);
    }
return(0);
}