#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, k, b = 0;
    cin >> a >> k;
    while (--k && b != a) {
      b = a;
      int ma = 0, mi = 10;
      while (a) {
        int p = a % 10;
        ma = max(ma, p);
        mi = min(mi, p);
        a /= 10;
      }
      a = b + ma * mi;
    }
    cout << a << "\n";
  }
  return 0;
}
