#include <bits/stdc++.h>
using namespace std;
long long int getMax(long long int n) {
  string s = "";
  while (n > 0) {
    s += to_string(n % 10);
    n = n / 10;
  }
  long long int maxN = 0;
  for (char c : s) {
    maxN = max(maxN, (long long int)(c - '0'));
  }
  return maxN;
}
long long int getMin(long long int n) {
  string s = "";
  while (n > 0) {
    s += to_string(n % 10);
    n = n / 10;
  }
  long long int minN = 9;
  for (char c : s) {
    minN = min(minN, (long long int)(c - '0'));
  }
  return minN;
}
void solve() {
  long long int a, k;
  cin >> a >> k;
  long long int ans = a;
  for (long long int i = 0; i < k - 1; i++) {
    long long int mn = getMin(ans);
    long long int mx = getMax(ans);
    if (mn == 0) {
      break;
    }
    ans = ans + mn * mx;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
