#include <bits/stdc++.h>
using namespace std;
long long mindigit(long long n) {
  long long smallest = 9;
  while (n) {
    long long r = n % 10;
    smallest = min(r, smallest);
    if (smallest == 0) {
      return 0;
    }
    n /= 10;
  }
  return smallest;
}
long long maxdigit(long long p) {
  long long largest = 0;
  while (p) {
    long long q = p % 10;
    largest = max(q, largest);
    if (largest == 9) {
      return 9;
    }
    p /= 10;
  }
  return largest;
}
int main() {
  long long t, a, k;
  cin >> t;
  while (t--) {
    cin >> a >> k;
    while (k > 1) {
      if (mindigit(a) * maxdigit(a) == 0) break;
      a += mindigit(a) * maxdigit(a);
      k--;
    }
    cout << a << endl;
  }
  return 0;
}
