#include <bits/stdc++.h>
using namespace std;
long long n, k;
void In() { cin >> n >> k; }
void Solve() {
  k--;
  while (k--) {
    int largest = INT_MIN, smallest = INT_MAX;
    for (long long copy = n; copy; copy /= 10) {
      int r = copy % 10;
      largest = max(r, largest);
      smallest = min(r, smallest);
    }
    if (largest == 0 || smallest == 0) return;
    n += largest * smallest;
  }
}
void Out() { cout << n << '\n'; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    In();
    Solve();
    Out();
  }
}
