#include <bits/stdc++.h>
using namespace std;

int main(){
  int num, n;
  string s1;
  while(cin >> num >> n, num | n){
    map<int, int> mp;
    int idx = 0;
    while(mp.find(num) == mp.end()){
      mp[num] = idx;
      stringstream s;
      s << num;
      s >> s1;
      string tmp;
      for(int i = 0; i < n - s1.size(); i++) tmp += "0";
      s1 = tmp + s1;
      sort(s1.begin(), s1.end());
      int mmin = atoi(s1.c_str());
      reverse(s1.begin(), s1.end());
      int mmax = atoi(s1.c_str());
      num = mmax - mmin;
      idx++;
    }
    cout << mp[num] << " " << num << " " << idx - mp[num] << endl;
  }
  return 0;
}

