#include <bits/stdc++.h>
using namespace std;
vector<long long> cal(long long a) {
  vector<long long> v(2);
  v[0] = 9;
  v[1] = 0;
  while (a) {
    int t = a % 10;
    a /= 10;
    if (t < v[0]) v[0] = t;
    if (t > v[1]) v[1] = t;
  }
  return v;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    long long sum = a;
    vector<long long> v(2);
    v = cal(a);
    k--;
    while (k-- && v[0] != 0) {
      sum += v[0] * v[1];
      v = cal(sum);
    }
    cout << sum << "\n";
  }
  return 0;
}
