#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    long long n, m;
    cin >> n >> m;
    long long cnt = 1, temp = n;
    while (1) {
      if (cnt == m) {
        cout << temp << endl;
        break;
      }
      int x = 9, y = 0;
      long long t = temp;
      while (t != 0) {
        int rem = t % 10;
        x = min(x, rem);
        y = max(y, rem);
        t /= 10;
      }
      cnt++;
      temp += (x * y);
      if (x * y == 0) {
        cout << temp << endl;
        break;
      }
    }
  }
  return 0;
}
