#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
long long int mm(long long int n) {
  long long int ma = 0, mi = 10;
  while (n > 0) {
    long long int x = n % 10;
    n /= 10;
    mi = min(mi, x);
    ma = max(ma, x);
  }
  return mi * ma;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long int a, k;
    cin >> a >> k;
    k--;
    while (k--) {
      long long int y = mm(a);
      if (y == 0) break;
      a += y;
    }
    cout << a << '\n';
  }
}
