//
//  main.c
//  Recurring Decimals
//
//  Created by x15071xx on 2016/06/09.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>


void swap(int x,int y){
    int tmp;
    tmp = x;
    x = y;
    y= tmp;
}

int main(int argc, const char * argv[]) {
    
    
    while (1) {
        
        int i,j;
        int dai_array[6]={0},sho_array[6]={0},dai_1=0,sho_1=0;
        int a,keta,bu=1;
        int array_a[20]={0},count=1,tmp,c=0;

        scanf("%d %d",&a,&keta);
        
        if (a==0&&keta==0) {
            break;
        }
        
        array_a[0] = a;
        
        while (count != 20) {
            
            bu=1;
            for (i=0; i<keta-1; i++) {
                bu*=10;
            }
            
            for (i=0; i<keta; i++) {
                dai_array[i] = a/bu;
                sho_array[i] = a/bu;
                a = a - bu*dai_array[i];
                bu = bu /10;
            }
            
            for (i=0; i<keta-1; i++) {
                for (j=keta-1; j>i; j--) {
                    if (dai_array[j-1] < dai_array[j]) {
                        //swap(dai_array[j-1],dai_array[j]);
                        tmp = dai_array[j-1];
                        dai_array[j-1] = dai_array[j];
                        dai_array[j] = tmp;
                    }
                    if (sho_array[j-1] > sho_array[j]) {
                        //swap(sho_array[j-1],sho_array[j]);
                        tmp = sho_array[j-1];
                        sho_array[j-1] = sho_array[j];
                        sho_array[j] = tmp;
                        
                    }
                }
            }
            bu=1;
            for (i=0; i<keta-1; i++) {
                bu*=10;
            }
            dai_1 = 0;
            sho_1 = 0;
            for (i=0; i<keta; i++) {
                dai_1 +=dai_array[i] * bu;
                sho_1 +=sho_array[i] * bu;
                
                bu = bu/10;
            }
            
            a = dai_1 - sho_1;
            
            array_a[count] = a;
            count++;
        }
        
        for (i = 1; i < 21; i++) {
            for (j=0; j < i; j++) {
                if (array_a[i] == array_a[j]) {
                    printf("%d %d %d\n",j,array_a[i],i-j);
                    c=1;
                    break;
                }
            }
            if (c==1) {
                break;
            }
        }
    }
    return 0;
}