#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  uint64_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
#pragma warning(disable : 4996)
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  for (auto& i : v) cout << i << " ";
  return os;
}
long long bp(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
vector<int> zf(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
long long mod(long long a, long long b) { return ((a % b) + b) % b; }
long long max_n(long long a) {
  long long res = 0;
  while (a) {
    res = max(res, a % 10ll);
    a /= 10ll;
  }
  return res;
}
long long min_n(long long a) {
  long long res = 9;
  while (a) {
    res = min(res, a % 10ll);
    a /= 10ll;
  }
  return res;
}
void solve() {
  long long a, k;
  cin >> a >> k;
  for (long long i = 0; i < k - 1; i++) {
    long long dif = min_n(a) * max_n(a);
    if (!dif) break;
    a += dif;
  }
  cout << a << "\n";
}
int main() {
  cout.tie(0);
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  for (int c = 1; c < (int)(t + 1); c++) {
    solve();
  }
}
