#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string a;
    long long k, l, s;
    char ma, mi;
    cin >> a >> k;
    if (k == 1) {
      cout << a << endl;
    } else {
      for (int i = 0; i < k - 1; i++) {
        l = a.size();
        ma = a[0];
        mi = a[0];
        for (int j = 1; j < l; j++) {
          if (a[j] > ma) {
            ma = a[j];
          }
        }
        for (int j = 1; j < l; j++) {
          if (a[j] < mi) {
            mi = a[j];
          }
        }
        int ma2 = ma - '0';
        int mi2 = mi - '0';
        if (mi2 == 0) {
          break;
        } else {
          stringstream ssr(a);
          ssr >> s;
          s += ma2 * mi2;
          stringstream sr;
          sr << s;
          sr >> a;
        }
      }
      cout << a << endl;
    }
  }
  return 0;
}
