#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long __gcd(long long a, long long b) {
  if (a == 0) return b;
  return __gcd(b % a, a);
}
pair<long long, long long> mx_mn(long long x) {
  vector<long long> v;
  while (x) {
    v.push_back(x % 10);
    x /= 10;
  }
  return make_pair(*max_element(v.begin(), v.end()),
                   *min_element(v.begin(), v.end()));
}
void solve() {
  long long a, k, ans;
  cin >> a >> k;
  ans = a;
  k--;
  while (k--) {
    pair<long long, long long> p = mx_mn(ans);
    if (p.second == 0 || p.first == 0) break;
    ans += p.first * p.second;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
