#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &istream, vector<T> &v) {
  for (auto &it : v) cin >> it;
  return istream;
}
template <typename T>
ostream &operator<<(ostream &ostream, const vector<T> &c) {
  for (auto &it : c) cout << it << " ";
  return ostream;
}
long long int mult(long long int a, long long int b,
                   long long int p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long int add(long long int a, long long int b,
                  long long int p = 1000000007) {
  return (a % p + b % p) % p;
}
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
long long int i, j;
void solve() {
  long long int a, k;
  cin >> a >> k;
  long long int mini, maxi;
  --k;
  while (k--) {
    string g = to_string(a);
    mini = *min_element((g).begin(), (g).end()) - '0';
    maxi = *max_element((g).begin(), (g).end()) - '0';
    if (mini == 0) break;
    a += mini * maxi;
  }
  cout << a << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
