#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long INF = 998244353;
long long mx(long long n) {
  long long m = INT_MIN;
  while (n) {
    m = max(m, n % 10);
    n /= 10;
  }
  return m;
}
long long mn(long long n) {
  long long m = INT_MAX;
  while (n) {
    m = min(m, n % 10);
    n /= 10;
  }
  return m;
}
int main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (int i = 1; i < k; i++) {
      long long m = mn(n);
      long long mn = mx(n);
      if (mn == 0 || m == 0) {
        break;
      }
      n += mn * m;
    }
    cout << n << "\n";
  }
}
