#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream &operator<<(ostream &out, const vector<A> &a) {
  for (const A &it : a) out << it << " ";
  return out;
}
template <class A, class B>
istream &operator>>(istream &in, pair<A, B> &a) {
  return in >> a.first >> a.second;
}
template <class A>
istream &operator>>(istream &in, vector<A> &a) {
  for (A &i : a) in >> i;
  return in;
}
ifstream cinn("input.txt");
ofstream coutt("output.txt");
long long f(long long n) {
  if (n == 0) return 0;
  long long mn = (1e18), mx = -(1e18);
  while (n) {
    mn = min(mn, n % 10);
    mx = max(mx, n % 10);
    n /= 10;
  }
  return mn * mx;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long a1, k;
    cin >> a1 >> k;
    long long lst = a1;
    long long ans = a1;
    for (long long i = 2; i <= k; i++) {
      ans += f(lst);
      lst = ans;
      if (f(lst) == 0) {
        break;
      }
    }
    cout << ans << "\n";
  }
}
