#include <bits/stdc++.h>
using namespace std;
set<int> si;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
unsigned long long hu(unsigned long long k) {
  vector<unsigned long long> v;
  for (unsigned long long i = 1; i < 100000000;) {
    if (k == 0) {
      break;
    }
    v.push_back(k % 10);
    k = k / 10;
  }
  sort(v.begin(), v.end());
  return v.front() * v.back();
}
void mi() {
  unsigned long long k, n;
  cin >> k >> n;
  for (unsigned long long i = 1; i < n; i++) {
    k = k + hu(k);
    if (hu(k) == 0) {
      break;
    }
  }
  cout << k << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  unsigned long long t;
  cin >> t;
  while (t--) {
    mi();
  }
}
