#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    if (k >= 2)
      for (long long i = 2; i <= k; i++) {
        long long minn = 9, maxx = 0;
        long long b = a;
        while (b > 0) {
          maxx = max(b % 10, maxx);
          minn = min(b % 10, minn);
          b /= 10;
          if (minn == 0) break;
        }
        if (minn == 0)
          break;
        else
          a += minn * maxx;
      }
    cout << a << endl;
  }
}
