#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int a1;
  cin >> a1;
  long long int k;
  cin >> k;
  while (k > 1) {
    long long int temp = a1;
    long long int mind, maxd;
    mind = INT_MAX;
    maxd = INT_MIN;
    while (temp > 0) {
      int n = temp % 10;
      if (n > maxd) {
        maxd = n;
      }
      if (n < mind) {
        mind = n;
      }
      temp = temp / 10;
    }
    a1 = a1 + mind * maxd;
    k--;
    if (mind == 0) {
      break;
    }
  }
  cout << a1 << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
