#include <bits/stdc++.h>
using namespace std;
vector<long long> return_digit(long long num) {
  vector<long long> arr;
  while (num != 0) {
    long long rem = num % 10;
    arr.push_back(rem);
    num /= 10;
  }
  return arr;
}
long long product_minmax(vector<long long> v) {
  long long max_val = v[0];
  long long min_val = v[0];
  for (long long i = 1; i < v.size(); i++) {
    max_val = max(max_val, v[i]);
    min_val = min(min_val, v[i]);
  }
  return max_val * min_val;
}
long long compute(long long num) {
  return num + product_minmax(return_digit(num));
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a1, k;
    cin >> a1 >> k;
    long long temp = a1;
    long long i = 0;
    long long prev = a1;
    while (i < k - 1) {
      prev = temp;
      temp = compute(temp);
      if (prev == temp) {
        break;
      }
      i += 1;
    }
    cout << temp << endl;
  }
  return 0;
}
