#include <bits/stdc++.h>
using namespace std;
int mi_f(vector<int> v) {
  int mi = 9, i;
  for (i = 0; i < v.size(); i++) mi = min(mi, v[i]);
  return mi;
}
int ma_f(vector<int> v) {
  int ma = 0, i;
  for (i = 0; i < v.size(); i++) ma = max(ma, v[i]);
  return ma;
}
vector<int> add_f(vector<int> v, int p) {
  int i, j;
  v[0] += p;
  int l = 0;
  for (i = 0; i < v.size(); i++) {
    v[i] += l;
    if (v[i] > 9) {
      l = v[i] / 10;
      v[i] = v[i] % 10;
    } else
      l = 0;
  }
  if (l > 0) v.push_back(l);
  return v;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, j;
    long long int m, a, k, l;
    cin >> a >> k;
    vector<int> v;
    while (a > 0) {
      int p = a % 10;
      a = a / 10;
      v.push_back(p);
    }
    for (i = 1; i < k; i++) {
      int mi = mi_f(v);
      int ma = ma_f(v);
      if (mi == 0) break;
      v = add_f(v, mi * ma);
    }
    for (i = v.size() - 1; i > -1; i--) cout << v[i];
    cout << "\n";
  }
  return 0;
}
