#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
int nooffac(long long a) {
  int c = 0;
  for (int i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      c++;
      if (a / i != i) c++;
    }
    return c;
  }
}
long long check(long long val) {
  long long k2 = val;
  long long t = 0;
  long long sum = 0;
  val = val - val % 5;
  while (k2 > 0) {
    k2 = k2 / 5;
    t++;
  }
  t--;
  long long k1 = pow(5, t);
  while (k1 >= 5) {
    sum += val / k1;
    k1 = k1 / 5;
  }
  return sum;
}
long long bi_search(long long k) {
  long long low = 0;
  long long high = 1e12;
  long long pos;
  while (high > low) {
    long long mid = (low + high) / 2;
    if (check(mid) >= k) {
      pos = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  return pos;
}
int main() {
  long long n;
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    int i1 = 2;
    while (i1 <= b) {
      long long k = a;
      long long m1 = INT_MAX;
      long long m2 = INT_MIN;
      while (k) {
        m1 = min(k % 10, m1);
        m2 = max(k % 10, m2);
        k /= 10;
      }
      a += m1 * m2;
      if (m1 == 0) break;
      i1++;
    }
    cout << a << endl;
  }
}
