#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int t;
  cin >> t;
  while (t--) {
    ll a, K;
    cin >> a >> K;
    for (ll i = 1; i < K; ++i) {
      ll x = a;
      int max_val = -1, min_val = 10;
      while (x) {
        int y = x % 10;
        max_val = max(y, max_val);
        min_val = min(y, min_val);
        x /= 10;
      }
      a += max_val * min_val;
      if (max_val == 0 || min_val == 0) {
        break;
      }
    }
    cout << a << endl;
  }
  return 0;
}
