#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  k--;
  while (k--) {
    long long N = n;
    long long mx = -1, mi = 10;
    while (N > 0) {
      mx = max(mx, N % 10);
      mi = min(mi, N % 10);
      N /= 10;
    }
    n += (mi * mx);
    if (mi == 0) break;
  }
  cout << n << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
