#include <bits/stdc++.h>
using namespace std;
int mind(long long x) {
  long long int m, r;
  m = 9;
  while (x != 0) {
    r = x % 10;
    x = x / 10;
    if (r == 0) {
      return r;
    }
    m = min(m, r);
  }
  return m;
}
int maxd(long long y) {
  long long int k, s;
  k = 0;
  while (y != 0) {
    s = y % 10;
    y = y / 10;
    if (s == 9) {
      return s;
    }
    k = max(k, s);
  }
  return k;
}
int main() {
  long long n, l, c, k, t, i, p;
  cin >> t;
  while (t--) {
    p = 1;
    cin >> n;
    cin >> k;
    l = mind(n);
    c = maxd(n);
    for (i = 1; i < k; i++) {
      if (l == 0) {
        cout << n << endl;
        p = 0;
        break;
      }
      n = n + l * c;
      l = mind(n);
      c = maxd(n);
    }
    if (p) {
      cout << n << endl;
    }
  }
}
