#include <bits/stdc++.h>
using namespace std;
signed 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 = 0; i < k - 1; i++) {
      set<long long> order;
      long long next = n;
      while (n) {
        order.insert(n % 10);
        n /= 10;
      }
      n = next + (*order.begin()) * (*order.rbegin());
      if (*order.begin() == 0) break;
    }
    cout << n << endl;
  }
  return 0;
}
