#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, mini, maxi, temp;
    cin >> n >> k;
    for (int i = 1; i <= k - 1; i++) {
      mini = 9, maxi = -1;
      temp = n;
      while (temp > 0) {
        mini = min(mini, temp % 10);
        maxi = max(maxi, temp % 10);
        temp /= 10;
      }
      if (mini == 0) break;
      n += (mini * maxi);
    }
    cout << n << endl;
  }
  return 0;
}
