#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll getAdd(ll x) {
  ll m1 = 10, m2 = 0;
  while (x > 0) {
    ll y = x % 10;
    x /= 10;
    m1 = min(m1, y);
    m2 = max(m2, y);
  }
  return m1 * m2;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    ll x, k;
    scanf("%lld%lld", &x, &k);
    k--;
    while (k--) {
      ll y = getAdd(x);
      if (y == 0) break;
      x += y;
    }
    printf("%lld\n", x);
  }
  return 0;
}
