#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
const long long P = 998244353;
using namespace std;
inline void ckmax(long long &a, long long b) { a = max(a, b); }
inline void ckmin(long long &a, long long b) { a = min(a, b); }
inline void mulmod(long long &a, long long b) { a = 1ll * a * b % P; }
inline void addmod(long long &a, long long b) {
  long long t = a + b;
  a = (t >= P ? t - P : t);
}
inline long long ksm(long long a, long long b) {
  long long ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = 1ll * ans * a % P;
    a = 1ll * a * a % P;
  }
  return ans;
}
inline long long inv(long long a) { return ksm(a, P - 2); }
inline long long read() {
  long long num = 0, flag = 1;
  char c = ' ';
  for (; !isdigit(c); c = getchar())
    if (c == '-') flag = -1;
  for (; isdigit(c); num = num * 10 + c - 48, c = getchar())
    ;
  return num * flag;
}
const long long MAXN = 2e5 + 5;
inline long long check(long long &a) {
  long long t = a, mi = 9, mx = 0;
  while (t) {
    ckmin(mi, t % 10);
    ckmax(mx, t % 10);
    t /= 10;
  }
  a += mx * mi;
  if (mx * mi == 0) return 0;
  return 1;
}
signed main() {
  long long T = read();
  while (T--) {
    long long a = read(), b = read();
    b--;
    while (1) {
      if (!b) break;
      b--;
      if (!check(a)) break;
    }
    printf("%lld\n", a);
  }
  return 0;
}
