#include <bits/stdc++.h>
using namespace std;
long long nxt(long long x) {
  long long mn = 10;
  long long mx = 0;
  long long xx = x;
  while (x > 0) {
    mn = min(mn, x % 10);
    mx = max(mx, x % 10);
    x /= 10;
  }
  return xx + mn * mx;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a1, k;
    cin >> a1 >> k;
    k--;
    while (k--) {
      if (a1 == nxt(a1)) break;
      a1 = nxt(a1);
    }
    cout << a1 << '\n';
  }
}
