#include <bits/stdc++.h>
using namespace std;
int mul(long long int a) {
  int mi = 10, ma = 0;
  while (a != 0) {
    int d = a % 10;
    mi = min(mi, d);
    ma = max(ma, d);
    a /= 10;
  }
  return mi * ma;
}
int main() {
  int t = 0;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    k--;
    while (k--) {
      int mult = mul(n);
      if (mult == 0) {
        break;
      }
      n += mult;
    }
    std::cout << n << std::endl;
  }
  return 0;
}
