#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    long long ans = a;
    for (int i = 0; i < k - 1; i++) {
      long long mn = 1LL << 63 - 1;
      long long mx = -1;
      long long temp = a;
      while (a) {
        long long num = a % 10;
        a = a / 10;
        mn = min(mn, num);
        mx = max(mx, num);
      }
      a = temp;
      a = a + mn * mx;
      if (mn == 0) break;
      ans += mn * mx;
    }
    cout << ans << "\n";
  }
  return 0;
}
