#include <bits/stdc++.h>
using namespace std;
long long int solve(long long int a) {
  long long int n = a, maxv = 0, minv = 9, digit;
  while (n != 0) {
    digit = n % 10;
    if (digit > maxv) maxv = digit;
    if (digit < minv) minv = digit;
    n /= 10;
  }
  return a += minv * maxv;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int a, k, ans;
    cin >> a >> k;
    k--;
    while (k--) {
      ans = solve(a);
      if (ans == a) break;
      a = ans;
    }
    cout << a << endl;
  }
  return 0;
}
