/*
 * Copyright (C) 2012, 2016  Hiroyasu Kamo
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * ACM-ICPC 2012 Japan Domestic Contest
 *  Problem B  Recurring Decimals
 *
 *	Author: Hiroyasu Kamo <wd@ics.nara-wu.ac.jp>
 */

#include <algorithm>
#include <functional>
#include <iterator>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <iomanip>
using std::find;
using std::sort;
using std::less;
using std::greater;
using std::distance;
using std::string;
using std::vector;
using std::cin;
using std::cout;
using std::istringstream;
using std::ostringstream;
using std::setfill;
using std::setw;

class rd {
private:
	int	len;
public:
	explicit rd(int l) : len(l) {}
	int	operator()(int) const;
};

int
rd::operator()(int x) const
{
	ostringstream	buf;
	buf << setfill('0') << setw(len) << x;
	string	str1 = buf.str();
	sort(str1.begin(), str1.end(), less<char>());
	int	m;
	istringstream(str1) >> m;
	reverse(str1.begin(), str1.end());
	int	n;
	istringstream(str1) >> n;
	return n - m;
}

int
main()
{
	for (int a0, l; cin >> a0 >> l && !(a0 == 0 && l == 0); ) {
		const rd	f(l);
		for (vector<int> a = {a0} ;;) {
			const int	an = f(a.back());
			const auto	p = find(a.begin(), a.end(), an);
			if (p != a.end()) {
				cout << distance(a.begin(), p) << " "
				     << an << " "
				     << distance(p, a.end()) << "\n";
				break;
			}
			a.push_back(an);
		}
	}
	return 0;
}
