/*
ID: zhaowei10
TASK:
LANG: C++14
*/
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
#include <debug.h>
#else
#define debug(...) 0
#endif

#define f first
#define s second
#define eb emplace_back

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;
using vc = vector<char>;
using vb = vector<bool>;
using vll = vector<ll>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

#ifdef LOCAL
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#else
#endif

  int t;
  cin >> t;
  while (t--) {
    ll a, k;
    cin >> a >> k;
    for (ll i = 1; i < k && a; ++i) {
      ll max_dig = 0, min_dig = 9;
      for (ll j = a; j; j /= 10) {
        max_dig = max(max_dig, j % 10);
        min_dig = min(min_dig, j % 10);
      }
      if (max_dig * min_dig == 0)
        break;
      a += max_dig * min_dig;
    }
    cout << a << '\n';
  }
}
