#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long a, k, maxn = 0, minn = 10;
    cin >> a >> k;
    if (k == 1) {
      cout << a << endl;
    } else {
      k--;
      long long a1 = a;
      for (; k > 0; k--) {
        maxn = 0, minn = 10;
        while (a1 != 0) {
          if (minn > a1 % 10) minn = a1 % 10;
          if (maxn < a1 % 10) maxn = a1 % 10;
          a1 /= 10;
        }
        if (minn == 0) {
          cout << a << endl;
          break;
        }
        a1 = a + minn * maxn;
        a = a1;
      }
      if (minn != 0) {
        cout << a << endl;
      }
    }
  }
  return 0;
}
