#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, k, dig, mm, ma;
    cin >> n >> k;
    long long int ans = 0;
    for (long long int i = 1; i < k; i++) {
      long long int temp = n + ans;
      mm = 9, ma = 0;
      while (temp > 0) {
        dig = temp % 10;
        mm = min(mm, dig);
        ma = max(ma, dig);
        temp /= 10;
      }
      if ((mm * ma) == 0)
        break;
      else
        ans += mm * ma;
    }
    cout << (n + ans) << endl;
  }
}
