using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using CHY72;

namespace CHY72{
    
    public class PointXY<T>where T:IComparable  {
        public T X , Y;
        public bool Flag = false;
        public PointXY(T _X,T _Y) {
            X = _X; Y = _Y;
        }
        public static bool operator ==(PointXY<T> P1, PointXY<T> P2) {
            return (P1.X.CompareTo( P2.X) == 0 && P1.Y.CompareTo (P2.Y) == 0);
        }
        public static bool operator !=(PointXY<T> P1, PointXY<T> P2) {return !(P1 ==P2);}
        public override int GetHashCode() {return X.GetHashCode() ^ Y.GetHashCode();}
        public override bool Equals(object obj) {
            if (obj == null || this.GetType() != obj.GetType()) {return false;}
            return (this == (PointXY<T>)obj);
        }
        //char '0' == int 48 ;....;char '9' == int 57;

    }

    public class Lib72 {
        public static int NumFromChar(char CNUM) { return CNUM - 48; }

        public static int[] KETAArray(int Num) {return KETAArray(Num.ToString()); }
        public static int[] KETAArray(string Num) {
            char[] cKETA = Num.ToCharArray();
            int[] iKETA = new int[cKETA.Length];
            for (int i = 0; i < iKETA.Length; i++) {
                iKETA[i] = NumFromChar(cKETA[i]);
            }
            return iKETA;
        }
        public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; }
        public static int FromKETAArray(int[] _ketaarray) {
            int result = 0;
            int[] R_ketaarray = _ketaarray.Reverse().ToArray(); 
            for (int i = 0,j=1; i < R_ketaarray.Length; i++,j *=10) {
                result += j * R_ketaarray[i];
            }
            return result;
        }
    }
}    

public class Program {
    static bool ReadLine_1(ref int num1, bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str);
        return (Fin0 && num1 == 0);
    }
    static int  ReadLine_1() {
        return  int.Parse(Console.ReadLine());
    }
    static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) {
        string str = Console.ReadLine();
        num1 = int.Parse(str.Split(Spliter)[0]);
        num2 = int.Parse(str.Split(Spliter)[1]);
        return (Fin0 && num1 == 0 && num2 == 0);
    }
    static int[] ReadLine72(char Spliter = ' ') {
        return Console.ReadLine().Split(Spliter).Select(s => int.Parse(s)).ToArray();
    }

    const int DefaultMax = 72727272;
    


    static void Main(string[] args) {
        while (true) {
            int a = 0, l = 0;
            if (ReadLine_2(ref a, ref l)) return;
            int[] aArray = new int[30];
            aArray[0] = a;
            int ii=0,jj=0;
            for(int i= 0 ; i < 25;i ++){
                string astr = "" + aArray[i];
                for (int iiii = Lib72.KETA(aArray[i]); iiii < l; iiii++) { astr = "0" + astr; }
                int[] DefaultNum = Lib72.KETAArray(astr);
                int[] MinNum = DefaultNum.OrderBy(x => x).ToArray();
                int[] MaxNum = MinNum.Reverse().ToArray ();
                //Console.WriteLine(i);
                //Console.WriteLine("DEF::" + Lib72.FromKETAArray(DefaultNum));
                //Console.WriteLine("MAX::"+Lib72.FromKETAArray(MaxNum));
                //Console.WriteLine("MIN::"+Lib72.FromKETAArray(MinNum));
                //Console.WriteLine("NEXT:" + (Lib72.FromKETAArray(MaxNum) - Lib72.FromKETAArray(MinNum)));
                aArray[i + 1] = Lib72.FromKETAArray(MaxNum) - Lib72.FromKETAArray(MinNum);
                bool OK = false;
                for (int j = 0; j < i; j++) {
                    if (aArray[i] == aArray[j]) { ii = i; jj = j; OK = true; break; }
                }
                if (OK) break;
            }
            Console.WriteLine(jj+ " "+ aArray[ii]  + " " + (ii - jj));
        }
    }
}

Measured memory_bytes: 20856