#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll p(ll a) {
  ll x = 10;
  ll y = -1;
  while (a > 0) {
    x = min(a % 10, x);
    y = max(a % 10, y);
    a /= 10;
  }
  return x * y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    ll a, k;
    cin >> a >> k;
    k--;
    while (k--) {
      a += p(a);
      if (p(a) == 0) break;
    }
    cout << a << '\n';
  }
}
