#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    for (long long int i = 2; i <= k; i++) {
      long long int x = 9, y = 0, p = n;
      while (p) {
        x = min(x, p % 10);
        y = max(y, p % 10);
        p /= 10;
      }
      if (!x) break;
      n += (x * y);
    }
    cout << n << endl;
  }
  return 0;
}
