#include <bits/stdc++.h>
using namespace std;
unsigned long long multiply(unsigned long long n) {
  unsigned long long minm = 9, maxm = 0;
  while (n > 0) {
    minm = min(minm, n % 10);
    maxm = max(maxm, n % 10);
    n /= 10;
  }
  return minm * maxm;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    unsigned long long a, n;
    cin >> a >> n;
    for (int i = 2; i <= n; i++) {
      unsigned long long addMinMaxDigits = multiply(a);
      if (addMinMaxDigits == 0) {
        break;
      } else
        a += addMinMaxDigits;
    }
    cout << a << endl;
  }
  return 0;
}
