#include <bits/stdc++.h>
using namespace std;
long long int mind(long long int a) {
  long long int m = 9;
  while (a) {
    long long int x = a % 10;
    m = min(m, x);
    a /= 10;
  }
  return m;
}
long long int maxd(long long int a) {
  long long int m = -1;
  while (a) {
    long long int x = a % 10;
    m = max(m, x);
    a /= 10;
  }
  return m;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, k;
    cin >> a >> k;
    long long int i = 1;
    while (i < k and mind(a) != 0) {
      a = a + maxd(a) * mind(a);
      i++;
    }
    cout << a << endl;
  }
}
