#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    for (int i = 1; i < k; i++) {
      if (k == 1) {
        cout << a << endl;
        break;
      }
      int minv = 10;
      int maxv = -1;
      long long s = a;
      while (s > 0) {
        int temp = s % 10;
        minv = min(minv, temp);
        maxv = max(maxv, temp);
        s = s / 10;
      }
      if (minv == 0) {
        break;
      }
      a = a + minv * maxv;
    }
    cout << a << endl;
  }
  return 0;
}
