#include <bits/stdc++.h>
using namespace std;
pair<int, int> findMaxMin(long long int a) {
  int mini = 100;
  int maxi = -100;
  while (a > 0) {
    int digit = a % 10;
    if (digit > maxi) {
      maxi = digit;
    }
    if (digit < mini) {
      mini = digit;
    }
    a = a / 10;
  }
  return make_pair(maxi, mini);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int an, k;
    cin >> an >> k;
    long long int prev = an;
    long long int next = an;
    for (long long int i = 2; i <= k; i++) {
      pair<int, int> mxmn = findMaxMin(prev);
      next = prev + (mxmn.first * mxmn.second);
      if (prev == next) break;
      prev = next;
    }
    cout << next << endl;
  }
  return 0;
}
