#include <bits/stdc++.h>
using namespace std;
void getmx(long long n, vector<int> &V) {
  V.clear();
  while (n > 0) {
    V.push_back(n % 10);
    n /= 10;
  }
}
long long getNK(long long n, long long k) {
  vector<int> V;
  int minv, maxv;
  for (long long i = 1; i < k; i++) {
    getmx(n, V);
    minv = *min_element(V.begin(), V.end());
    maxv = *max_element(V.begin(), V.end());
    if (minv == 0)
      break;
    else
      n += minv * maxv;
  }
  return n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  long long n, k;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    cout << getNK(n, k) << endl;
  }
  return 0;
}
