#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
void suraj() {
  unsigned long long a, k;
  cin >> a >> k;
  for (int i = 1; i < k; i++) {
    unsigned long long b = a;
    int mx = 0;
    int mn = 9;
    while (b > 0) {
      mn = min(int(b % 10), mn);
      mx = max(int(b % 10), mx);
      b = b / 10;
      if (mn == 0) {
        cout << a << "\n";
        return;
      }
    }
    a = a + mn * mx;
  }
  cout << a << "\n";
}
int main() {
  startTime = (double)clock();
  int t;
  cin >> t;
  while (t--) suraj();
  return 0;
}
