#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int calc(int a, int n) {
  vector<int> v(n);
  REP(i, n) {
    v[i] = a % 10;
    a /= 10;
  }
  sort(begin(v), end(v));
  int mn = 0;
  int mx = 0;
  REP(i, n) {
    int j = n - i - 1;
    mn = 10 * mn + v[i];
    mx = 10 * mx + v[j];
  }
  return mx - mn;
}

int main() {
  for (int a, l; cin >> a >> l, l;) {
    map<int, int> mp;
    REP(i, 21) {
      if (mp.find(a) != end(mp)) {
        cout << mp[a] << ' ' << a << ' ' << i - mp[a] << endl;
        break;
      }
      mp[a] = i;
      a = calc(a, l);
    }
  }
}

