#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast", "-funroll-all-loops")
using namespace std;
long long a, k, res;
inline long long check(long long x) {
  while (x) {
    if (x % 10 == 0) return 1;
    x /= 10;
  }
  return 0;
}
inline long long f(long long x) {
  long long res = 0;
  while (x) res = max(res, x % 10), x /= 10;
  return res;
}
inline long long g(long long x) {
  long long res = 10;
  while (x) res = min(res, x % 10), x /= 10;
  return res;
}
inline void solve() {
  cin >> a >> k;
  res = k;
  if (k == 1) return printf("%lld\n", a), void();
  for (long long i = 2; i <= k; i++) {
    if (check(a)) break;
    a = a + f(a) * g(a);
  }
  printf("%lld\n", a);
}
signed main() {
  long long T;
  cin >> T;
  while (T--) solve();
  return 0;
}
