#include <bits/stdc++.h>
using namespace std;
long long int arr[2000000];
bool compare(long long int a, long long int b) { return a > b; }
long long int ans[2000000];
bool checkzero(long long int n) {
  while (n > 0) {
    if (n % 10 == 0) return true;
    n = n / 10;
  }
  return false;
}
pair<long long int, long long int> checkminmax(long long int n) {
  long long int m = LONG_LONG_MAX;
  long long int M = LONG_LONG_MIN;
  while (n > 0) {
    M = max(M, n % 10);
    m = min(m, n % 10);
    n /= 10;
  }
  return make_pair(m, M);
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int newn;
    newn = n;
    while (k > 1) {
      newn = n + checkminmax(n).first * checkminmax(n).second;
      if (newn == n)
        break;
      else {
        n = newn;
      }
      k--;
    }
    cout << newn << "\n";
  }
}
