#include <bits/stdc++.h>
using namespace std;
long long GcdRecursive(long long a, long long b) {
  if (b == 0) return a;
  return GcdRecursive(b, a % b);
}
const long long mod = 1e9 + 7;
int dirX[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dirY[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const long long MOD = 998244353;
const long long N = 2e5 + 7;
const long long LLinf = 1e18 + 5;
const int INTinf = 1e8 + 7;
long long t, n, m, a, b, k, c = 0, d, x, y;
long long x11, x22, y11, y22;
long long get(long long a) {
  long long mn = 9, mx = 0;
  while (a > 0) {
    long long x = a % 10;
    a /= 10;
    mn = min(x, mn);
    mx = max(x, mx);
  }
  return mn * mx;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> a >> k;
    k--;
    while (k--) {
      long long ans = get(a);
      if (ans == 0) break;
      a += ans;
    }
    cout << a << "\n";
  }
}
