#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 228;
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n, k;
    cin >> n >> k;
    --k;
    while (k--) {
      long long mn = 9, mx = 0;
      long long j = n;
      while (j) mn = min(mn, j % 10), mx = max(mx, j % 10), j /= 10;
      if (mn == 0) break;
      n += mn * mx;
    }
    cout << n << '\n';
  }
}
