#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long count = 0;
    while (count < k - 1) {
      long long mn = 10, mx = 0;
      long long a = n;
      while (a) {
        long long b = a % 10;
        mn = min(mn, b);
        mx = max(mx, b);
        a /= 10;
      }
      n += mn * mx;
      count++;
      if (mn == 0) break;
    }
    cout << n << endl;
  }
  return 0;
}
