#include <bits/stdc++.h>
using namespace std;
long long largest;
long long smallest;
void Digits(long long n) {
  largest = 0;
  smallest = 9;
  while (n) {
    long long r = n % 10;
    largest = max(r, largest);
    smallest = min(r, smallest);
    n = n / 10;
  }
  return;
}
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    solve();
  }
  return 0;
}
void solve() {
  long long a, k;
  cin >> a >> k;
  k--;
  largest = 0;
  smallest = 9;
  while (k--) {
    Digits(a);
    if (largest == 0 || smallest == 0) {
      break;
    }
    a += ((largest) * (smallest));
  }
  cout << a << endl;
  return;
}
