#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    long long n, k, k2 = 0;
    cin >> n >> k;
    map<long long, long long> a;
    a[1] = n;
    for (long long i = 2; i <= k; ++i) {
      long long k1 = a[i - 1], mn = 10, mx = 0;
      while (k1 > 0) {
        mn = min(mn, k1 % 10);
        mx = max(mx, k1 % 10);
        k1 /= 10;
      }
      a[i] = mn * mx + a[i - 1];
      if (mn == 0) {
        cout << a[i] << "\n";
        k2++;
        break;
      }
    }
    if (k2 == 0) cout << a[k] << "\n";
  }
  return 0;
}
