#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t) {
    long long int n, k, product = 1, i = 1, sum, copy, minimum = 10,
                        maximum = -1;
    cin >> n >> k;
    copy = sum = n;
    for (i = 2; i <= k; i++) {
      while (copy > 0) {
        minimum = min(minimum, copy % 10);
        maximum = max(maximum, copy % 10);
        copy /= 10;
      }
      product = minimum * maximum;
      sum = sum + product;
      copy = sum;
      if (product == 0) break;
      minimum = 10;
      maximum = -1;
    }
    cout << sum << endl;
    t--;
  }
}
