#include <bits/stdc++.h>
using namespace std;
long long prime(long long n) {
  if (n <= 1) return 0;
  if (n <= 3) return 1;
  if (n % 2 == 0 || n % 3 == 0) return 0;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return 0;
  return 1;
}
int main() {
  long long t;
  cin >> t;
  long long n, k, i, j, min, max, temp;
  while (t--) {
    cin >> n >> k;
    for (i = 1; i < k; i++) {
      temp = n;
      min = INT_MAX;
      max = INT_MIN;
      while (temp > 0) {
        j = temp % 10;
        if (j > max) max = j;
        if (j < min) min = j;
        temp = temp / 10;
      }
      if (min == 0) break;
      n = n + max * min;
    }
    cout << n << endl;
  }
}
