#include <bits/stdc++.h>
using namespace std;
vector<long long> al[100001];
long long vis[100001];
long long no(long long num) {
  long long min = num % 10, max = num % 10;
  while (num > 0) {
    long long a = num % 10;
    num /= 10;
    if (min > a) min = a;
    if (max < a) max = a;
  }
  return min * max;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, k;
    cin >> a >> k;
    for (long long i = 0; i < k - 1; i++) {
      long long b = no(a);
      if (b == 0) break;
      a += b;
    }
    cout << a << endl;
  }
}
