#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long double PI = acosl(-1);
const long long infl = 1e17 + 100;
const int inf = 1e9 + 100;
const int nmax = 1e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  for (int ces = 1; ces <= tc; ces++) {
    long long a, k;
    cin >> a >> k;
    k--;
    while (k--) {
      vector<int> digs;
      long long x = a;
      while (x) digs.push_back(x % 10), x /= 10;
      sort(digs.begin(), digs.end());
      if (digs[0] == 0) break;
      a += digs[0] * digs.back();
    }
    cout << a << "\n";
  }
}
