#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
void solve() {
  int Q;
  cin >> Q;
  while (Q--) {
    ll A, K;
    cin >> A >> K;
    --K;
    while (K > 0) {
      ll mx = 0;
      ll mn = 9;
      ll At = A;
      while (At > 0) {
        ll r = At % 10;
        At /= 10;
        mx = max(mx, r);
        mn = min(mn, r);
      }
      if (mx * mn == 0) {
        break;
      }
      A += mx * mn;
      --K;
    }
    cout << A << "\n";
  }
}
int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  solve();
  cout << flush;
  return 0;
}
