#include <bits/stdc++.h>
int max_digit(long long n) {
  int rem;
  int high = -1;
  while (n != 0) {
    rem = n % 10;
    if (rem > high) high = rem;
    n /= 10;
  }
  return high;
}
int min_digit(long long n) {
  int rem;
  int low = 11;
  while (n != 0) {
    rem = n % 10;
    if (rem < low) low = rem;
    n /= 10;
  }
  return low;
}
using namespace std;
int main() {
  int t;
  long long a, k;
  cin >> t;
  while (t--) {
    cin >> a >> k;
    for (long long i = 2; i <= k; i++) {
      if (min_digit(a) == 0)
        break;
      else
        a = a + max_digit(a) * min_digit(a);
    }
    cout << a << endl;
  }
  return 0;
}
