#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    long long b = a;
    long long mi = 10, ma = -1;
    while (mi != 0 && k > 1) {
      mi = 10, ma = -1;
      b = a;
      while (b) {
        mi = min(mi, b % 10);
        ma = max(ma, b % 10);
        b /= 10;
      }
      a = a + mi * ma;
      k--;
    }
    cout << a << "\n";
  }
}
