#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    for (int i = 1; i < m; i++) {
      long long k = n, mi = 9, ma = 0;
      while (k) {
        mi = min(k % 10, mi);
        ma = max(k % 10, ma);
        k /= 10;
      }
      if (mi == 0)
        break;
      else
        n += mi * ma;
    }
    cout << n << endl;
  }
}
