#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    long long int a, k, temp, r;
    vector<long long int> vec;
    cin >> a >> k;
    k--;
    while (k--) {
      temp = a;
      while (temp > 0) {
        r = temp % 10;
        vec.push_back(r);
        temp /= 10;
      }
      sort(vec.begin(), vec.end());
      a = a + vec[0] * vec[vec.size() - 1];
      vec.clear();
      if (vec[0] == 0) break;
    }
    cout << a << "\n";
  }
}
