#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a, k;
  cin >> a >> k;
  long long int co = 1;
  while (co < k) {
    co += 1;
    long long int b = a, ma = INT_MIN, mi = INT_MAX;
    while (b) {
      long long int r = b % 10;
      mi = min(r, mi);
      ma = max(r, ma);
      b /= 10;
    }
    a = a + ma * mi;
    if (ma * mi == 0) {
      break;
    }
  }
  cout << a << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
