#include <bits/stdc++.h>
using namespace std;
long long go(long long n, long long type) {
  long long m = 9999999999999999;
  long long M = -9999999999999999;
  while (n > 0) {
    long long last = n % 10;
    m = min(m, last);
    M = max(M, last);
    n /= 10;
  }
  if (type == 1)
    return m;
  else
    return M;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long prev = n;
    k--;
    while (k--) {
      long long m = go(n, 1);
      long long M = go(n, 2);
      n = n + (m * M);
      if (prev == n) {
        break;
      } else {
        prev = n;
      }
    }
    cout << n << "\n";
  }
}
