import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto l = readInts();
		auto a0 = l[0];
		auto L = l[1];
		if(a0 == 0 && L == 0){
			return;
		}
		auto s = a0.to!string.rightJustify(L,'0');
		int[string] h;
		int i;
		while((s in h) is null) {
			h[s] = i;
			++i;
			auto nMax = s.dup.sort.reverse.to!int;
			auto nMin = s.dup.sort.to!int;
			s = (nMax-nMin).to!string.rightJustify(L,'0');
		}
		writeln(h[s], " ", s, " ", i-h[s]);
	}
}