#include <bits/stdc++.h>
using namespace std;
void calc(long long n, long long &mx, long long &mn) {
  while (n) {
    long long rem = n % 10;
    n /= 10;
    mn = min(mn, rem);
    mx = max(mx, rem);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, tc, cs = 1, n, m, k, cnt = 0, j, q, mn, mx;
  string s;
  cin >> tc;
  while (tc--) {
    cin >> n >> k;
    mn = 9LL;
    mx = 0LL;
    while (--k) {
      mn = 9LL;
      mx = 0LL;
      calc(n, mx, mn);
      n += mx * mn;
      if (mn == 0) break;
    }
    cout << n << endl;
  }
  return 0;
}
