#include <bits/stdc++.h>
using namespace std;
vector<long long> visited(200000, 0);
vector<long long> adj[200000];
long long prime[2000000];
long long M = 1000000007;
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void sieve(long long ending) {
  for (long long i = 2; i < ending; i++) prime[i] = 1;
  for (long long i = 2; i * i <= ending; i++) {
    if (prime[i] == 1) {
      for (long long j = 2 * i; j <= ending; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  prime[1] = 0;
}
long long ncrmodp(long long num, long long r) {
  long long C[r + 1];
  long long i, j;
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (i = 1; i <= num; i++) {
    for (j = min(i, r); j > 0; j--) {
      C[j] = ((C[j]) % M + (C[j - 1]) % M) % M;
    }
  }
  return C[r];
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x % M;
  while (y > 0) {
    if (y & 1) res = (res * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return res;
}
long long min(long long a, long long b) {
  if (a <= b) return a;
  return b;
}
long long max(long long a, long long b) {
  if (a >= b) return a;
  return b;
}
void solve() {
  long long a1, k;
  cin >> a1 >> k;
  k--;
  string s;
  while (k--) {
    s = to_string(a1);
    long long mini = 9;
    long long maxi = 0;
    for (long long i = 0; i < s.length(); i++) {
      mini = min(mini, s[i] - '0');
      maxi = max(maxi, s[i] - '0');
    }
    a1 = a1 + mini * maxi;
    if (mini == 0 || maxi == 0) break;
  }
  cout << a1 << endl;
}
int main() {
  boost();
  long long t;
  cin >> t;
  while (t--) solve();
}
