using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    

    class Program
    {
        //上位桁に0がある文字列を数値に
        static int Strval_To_Val(string str_val)
        {
            int val = 0;

            for(int i = 0; i < str_val.Length; i++)
            {
                if(str_val[i] != '0')
                {
                    val = int.Parse(str_val.Substring(i, str_val.Length - i));
                    break;
                }
            }

            return val;
        }

        //余った桁に0をつけた文字列
        static string Val_To_Str(int val, int L)
        {
            string str_val = val.ToString();
            string zeros = "";
            int num_zero = L - val.ToString().Length;

            for(int i = 0; i < num_zero; i++)
            {
                zeros += "0";
            }

            return zeros + str_val;
        }

        //最大値の文字列（上位桁に0あり）
        static string Max_Str(string str_val)
        {
            string max_str = "";

            List<char> ch_list = str_val.ToList();

            foreach(var c in ch_list.OrderByDescending(x => x))
            {
                max_str += c.ToString();
            }

            return max_str;
        }

        //最小値の文字列（上位桁に0あり）
        static string Min_Str(string str_val)
        {
            string min_str = "";

            List<char> ch_list = str_val.ToList();

            foreach (var c in ch_list.OrderBy(x => x))
            {
                min_str += c.ToString();
            }

            return min_str;
        }

        //val_aから次のa（数値next_val__a）を求める
        static int Next_A(int val_a, int L)
        {
            int next_val_a = 0;        

            string str_a = Val_To_Str(val_a, L);
            string max_str_a = Max_Str(str_a);
            string min_str_a = Min_Str(str_a);

            next_val_a = Strval_To_Val(max_str_a) - Strval_To_Val(min_str_a);

            return next_val_a;
        }
        
        static void Main(string[] args)
        {

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                string str_a0 = input[0];
                int L = int.Parse(input[1]);

                if (str_a0 == "0" && L == 0)
                {
                    break;
                }

                List<int> val_a_list = new List<int>();
                val_a_list.Add(Strval_To_Val(str_a0));

                int i = 0;
                int j = 0;
                int ai = 0;
                bool find = false;

                while (true)
                {
                    val_a_list.Add(Next_A(val_a_list.Last(), L));

                    int last_val = val_a_list.Last();
                    for(int k = 0; k < val_a_list.Count() - 1; k++)
                    {
                        if(last_val == val_a_list[k])
                        {
                            j = k;
                            i = val_a_list.Count() - 1;
                            ai = val_a_list[i];
                            find = true;
                            break;
                        }
                    }

                    if (find)
                    {
                        break;
                    }

                }


                Console.WriteLine($"{j} {ai} {i - j}");

            }
            
        }
    }
}


Measured memory_bytes: 16468