#include <bits/stdc++.h>
using namespace std;
long long mm(long long b) {
  long long mx = -1, mn = 10;
  while (b > 0) {
    long long y = b % 10;
    b = b / 10;
    mx = max(mx, y);
    mn = min(mn, y);
  }
  return mx * mn;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, k, ans = 0;
    cin >> a >> k;
    k--;
    while (k--) {
      ans = mm(a);
      a = a + ans;
      if (ans == 0) break;
    }
    cout << a << endl;
  }
}
