#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  int ch = getchar(), f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  if (f) x = -x;
}
const int inf = 0x3f3f3f3f;
int T;
long long a, k;
int main() {
  cin >> T;
  while (T--) {
    cin >> a >> k;
    k--;
    long long minx, maxx;
    minx = inf, maxx = -inf;
    long long cnt = 0;
    while (minx != 0 && cnt < k) {
      long long temp = a;
      minx = inf, maxx = -inf;
      while (temp) {
        minx = min(minx, temp % 10);
        maxx = max(maxx, temp % 10);
        temp /= 10;
      }
      a += minx * maxx;
      cnt++;
    }
    cout << a << endl;
  }
  return 0;
}
