#include <bits/stdc++.h>
using namespace std;
vector<bool> prime(200002, true);
vector<int> primes;
void SieveOfEratosthenes(long long n) {
  prime[0] = prime[1] = false;
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p]) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (prime[i]) primes.push_back(i);
  }
}
int min_ret(vector<int> &a) {
  int min = a[0];
  for (int i = 1; i < a.size(); i++) {
    if (min > a[i]) min = a[i];
  }
  return min;
}
int max_ret(vector<int> &a) {
  int max = a[0];
  for (int i = 1; i < a.size(); i++) {
    if (max < a[i]) max = a[i];
  }
  return max;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    for (int i = 0; i < k - 1; i++) {
      long long y = a;
      vector<int> num;
      while (y) {
        num.push_back(y % 10);
        y /= 10;
      }
      int z = num.size();
      if (min_ret(num) == 0)
        break;
      else {
        a += min_ret(num) * max_ret(num);
      }
    }
    cout << a << endl;
  }
  return 0;
}
