#include <bits/stdc++.h>
using namespace std;
long long int pro(long long int n) {
  long long int min = 9, i;
  long long int max = 0;
  string s = to_string(n);
  for (i = 0; i < s.size(); i++) {
    if (s[i] - '0' < min) min = s[i] - '0';
    if (s[i] - '0' > max) max = s[i] - '0';
  }
  return min * max;
}
int main() {
  long long int n, k, i, t, x;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    x = 1;
    while (k > 1 && x) {
      n = n + pro(n);
      x = pro(n);
      k--;
    }
    cout << n << endl;
  }
}
