#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const long long N = 2e5 + 7;
const long long M = 1e9 + 7;
const long long MAXN = 1e18 + 7;
const long long Mod = 998244353;
long long _, i, j, k, n, m, p, q, s, t, T, d, l, r, h, len, o, u, v, w, st, en,
    sx, sy, ma, mi, mod, sum, num, res, flag, cas, ret, mid, ans, cnt, now, nex,
    tmp;
long long a[N], c[N];
char ch;
vector<long long> g[N];
string s1, s2, s3;
signed main() {
  ios::sync_with_stdio(false);
  long long T = 1;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    tmp = n;
    for (i = 1; i < k; i++) {
      ma = 0;
      mi = 9;
      n = tmp;
      while (n != 0) {
        m = n % 10;
        ma = max(ma, m);
        mi = min(mi, m);
        n = n / 10;
      }
      if (mi == 0) break;
      tmp = tmp + ma * mi;
    }
    cout << tmp << endl;
  }
  return 0;
}
