#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, e, f, p, maxmax, minmin;
  cin >> a;
  while (a--) {
    cin >> e >> f;
    f--;
    while (f--) {
      p = e;
      maxmax = -1;
      minmin = 10;
      while (p) {
        maxmax = max(p % 10, maxmax);
        minmin = min(p % 10, minmin);
        p /= 10;
      }
      if (maxmax == 0 || minmin == 0) break;
      e += maxmax * minmin;
    }
    cout << e << endl;
  }
  return 0;
}
