#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int num = n;
  for (long long int i = 2; i <= k; ++i) {
    long long int mia = 10, maa = -1;
    long long int temp = num;
    while (temp) {
      mia = min(mia, temp % 10);
      maa = max(maa, temp % 10);
      temp = temp / 10;
    }
    if (mia == 0) {
      break;
    }
    num = num + mia * maa;
  }
  cout << num << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
