#include <bits/stdc++.h>
int product(long long a) {
  int maxi = 0, mini = 9, x, ans;
  long long temp = a;
  while (temp) {
    x = temp % 10;
    if (x < mini) mini = x;
    if (x > maxi) maxi = x;
    temp /= 10;
  }
  if (mini == 0) return 0;
  ans = mini * maxi;
  return ans;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  long long a, k, ans;
  int t;
  cin >> t;
  while (t--) {
    cin >> a >> k;
    k--;
    while (k--) {
      if (product(a) == 0)
        break;
      else {
        a += product(a);
      }
    }
    cout << a << "\n";
  }
  return 0;
}
