#include <bits/stdc++.h>
using namespace std;
int minMax(long long n) {
  int min = 9, max = 0;
  while (n != 0) {
    int d = n % 10;
    n /= 10;
    if (d > max) max = d;
    if (d < min) min = d;
  }
  return min * max;
}
int get(int x) {
  string s = to_string(x);
  int mn = 9, mx = 0;
  for (int i = 0; i < s.size(); i++) {
    mn = min(mn, (s[i] - '0'));
    mx = max(mx, (s[i] - '0'));
  }
  return mn * mx;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t, a, k;
  cin >> t;
  while (t--) {
    cin >> a >> k;
    while (k != 1) {
      int t = minMax(a);
      if (t == 0) break;
      a = a + t;
      k--;
    }
    cout << a << endl;
  }
}
