import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (1) {
        int a,L;
        scan(a,L);
        if (!L) return;
        solve(a,L);
    }
}

void solve(int a, int L) {
    auto as = new int[](21);
    as[0] = a;

    foreach (i ; 1 .. 21) {
        as[i] = calmax(as[i-1], L) - calmin(as[i-1], L);

        foreach (j ; 0 .. i) {
            if (as[i] == as[j]) {
                writeln(j, " ", as[i], " ", i-j);
                return;
            }
        }
    }
}

int calmax(int x, int L) {
    auto cnt = new int[](10);

    while (x > 0) {
        cnt[x % 10]++;
        x /= 10;
    }

    cnt[0] += max(0, L - cnt.sum);

    int res;
    foreach_reverse (i ; 0 .. 10) {
        foreach (j ; 0 .. cnt[i]) {
            res *= 10;
            res += i;
        }
    }

    debug {
        writeln(res);
    }

    return res;
}

int calmin(int x, int L) {
    auto cnt = new int[](10);

    while (x > 0) {
        cnt[x % 10]++;
        x /= 10;
    }

    cnt[0] += max(0, L - cnt.sum);
    
    int res;
    foreach (i ; 0 .. 10) {
        foreach (j ; 0 .. cnt[i]) {
            res *= 10;
            res += i;
        }
    }

    debug {
        writeln(res);
    }

    return res;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}