#include <bits/stdc++.h>
using namespace std;
void minmax(long long int a, int &m, int &mi) {
  m = 0;
  mi = 10;
  while (a > 0) {
    int r = a % 10;
    m = max(m, r);
    mi = min(mi, r);
    a = a / 10;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int a, k, prev, new1;
    int m, mi;
    cin >> a >> k;
    prev = a;
    new1 = a;
    for (int i = 1; i < k; i++) {
      minmax(prev, m, mi);
      if (mi == 0) break;
      new1 = prev + m * mi;
      prev = new1;
    }
    cout << new1 << endl;
  }
}
