#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5;
const long long OO = 1e18;
const long long mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (long long i = 1; i < k; i++) {
      long long M = 0, m = 10;
      long long N = n;
      while (N) {
        long long aux = N % 10;
        N /= 10;
        M = max(M, aux), m = min(m, aux);
      }
      n += M * m;
      if (M * m == 0) break;
    }
    cout << n << "\n";
  }
  return 0;
}
