#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  while (t--) {
    long long int a1, p = 1, K;
    cin >> a1 >> K;
    while (p != K) {
      long long int temp = a1;
      int min = 9, max = 0;
      while (temp > 0) {
        if (max < temp % 10) max = temp % 10;
        if (min > temp % 10) min = temp % 10;
        temp /= 10;
      }
      a1 = a1 + min * max;
      if (min == 0) break;
      p++;
    }
    cout << a1 << "\n";
  }
  return 0;
}
