#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int a, k, n;
    bool complete = false;
    cin >> a >> k;
    k--;
    while (k--) {
      long long int max = 0, min = 10;
      for (n = a; n != 0; n /= 10) {
        if (n % 10 > max) max = n % 10;
        if (n % 10 < min) min = n % 10;
      }
      if (max == 0 || min == 0) {
        complete = true;
        cout << a << "\n";
        break;
      } else
        a = a + min * max;
    }
    if (!complete) cout << a << "\n";
  }
  return 0;
}
