#include <bits/stdc++.h>
int minDig(uint64_t n) {
  int k = n % 10, min = k;
  n /= 10;
  while (n != 0) {
    k = n % 10;
    if (k <= min) min = k;
    n /= 10;
  }
  return min;
}
int maxDig(uint64_t n) {
  int k = n % 10, max = k;
  n /= 10;
  while (n != 0) {
    k = n % 10;
    if (k >= max) max = k;
    n /= 10;
  }
  return max;
}
int searchzero(uint64_t n) {
  while (n != 0) {
    if (n % 10 == 0) return 1;
    n /= 10;
  }
  return 0;
}
int main(void) {
  int t;
  uint64_t a, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%llu %llu", &a, &k);
    for (uint64_t i = 1; i < k; i++) {
      a += (minDig(a) * maxDig(a));
      if (searchzero(a) == 1) break;
    }
    printf("%llu\n", a);
  }
  return 0;
}
