import java.util.Scanner;
import java.util.StringTokenizer;

public class SeriesofCrimes {
	public static void main(String args[]) {
		new SeriesofCrimes();
	}

	public SeriesofCrimes() {
		Scanner in = new Scanner(System.in);
		int m, n;
		String line;
		line = in.nextLine();
		StringTokenizer st = new StringTokenizer(line);
		m = Integer.parseInt(st.nextToken());
		n = Integer.parseInt(st.nextToken());

		int r1x = -1, r2x = -1, r3x = -1;
		int r1y = -1, r2y = -1, r3y = -1;
		for (int i = 0; i < m; i++) {
			line = in.nextLine();
			for (int j = 0; j < n; j++) {
				if (line.charAt(j) == '*') {
					if (r1x == -1) {
						r1x = i;
						r1y = j;
					} else if (r2x == -1) {
						r2x = i;
						r2y = j;
					} else if (r3x == -1) {
						r3x = i;
						r3y = j;
					}
				}
			}
		}
		int r4x, r4y;
		if (r1y == r3y && r2x == r3x) {
			r4x = r1x;
			r4y = r2y;
		} else if (r1y == r2y && r2x == r3x) {
			r4x = r3x;
			r4y = r1y;
		} else if (r1x == r2x && r2y == r3y) {
			r4x = r1x;
			r4y = r3y;

		} else {
			r4x = r3x;
			r4y = r2y;
		}
		r4x++;
		r4y++;
		System.out.print(r4x + " " + r4y);
	}
}


import java.util.Scanner;
import java.util.StringTokenizer;

public class SeriesofCrimes {
	public static void main(String args[]) {
		new SeriesofCrimes();
	}

	public SeriesofCrimes() {
		Scanner in = new Scanner(System.in);
		int m, n;
		String line;
		line = in.nextLine();
		StringTokenizer st = new StringTokenizer(line);
		m = Integer.parseInt(st.nextToken());
		n = Integer.parseInt(st.nextToken());
		int r1x = -1, r2x = -1, r3x = -1;
		int r1y = -1, r2y = -1, r3y = -1;
		for (int i = 0; i < m; i++) {
			line = in.nextLine();
			for (int j = 0; j < n; j++) {
				if (line.charAt(j) == '*') {
					if (r1x == -1) {
						r1x = i;
						r1y = j;
					} else if (r2x == -1) {
						r2x = i;
						r2y = j;
					} else if (r3x == -1) {
						r3x = i;
						r3y = j;
					}
					else{
						break;
					}
				}
			}
		}
		int r4x, r4y;
		if (r1y == r3y && r2x == r3x) {
			r4x = r1x;
			r4y = r2y;
		} else if (r1y == r2y && r2x == r3x) {
			r4x = r3x;
			r4y = r1y;
		} else if (r1x == r2x && r2y == r3y) {
			r4x = r1x;
			r4y = r3y;
		} else {
			r4x = r3x;
			r4y = r2y;
		}
		r4x++;
		r4y++;
		System.out.print(r4x + "" + r4y);
	}
}


#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
   int n,m,a,b,c,d,e,f,p=0;
   cin>>n>>m;
   char s;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<m;j++)
       {
           cin>>s;
       if(s=='*')
       {
           p++;
           if(p==1)
           {
               a=i+1;
               b=j+1;
           }
           else if(p==2)
           {
               c=i+1;
               d=j+1;
           }
           else if(p==3)
           {
               e=i+1;
               f=j+1;
           }
       }
       }
   }
   if(a==e)
   {
       cout<<c<<" ";
   }
   else if(a==c)
   {
       cout<<e<<" ";

   }
   else if(c==e)
   {
       cout<<a<<" ";
   }
   if(b==d)
   {
       cout<<f<<" ";
   }
   else if(b==f)
   {
       cout<<d<<" ";

   }
   else if(d==f)
   {
       cout<<b<<" ";
   }
   return 0;
}


#include<iostream>
#include<string>
using namespace std;
int aa[5][2];
string str;
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>str;
		for(int j=0;j<m;j++){
			if(str[j]=='*'){
				aa[k][0]=i;aa[k++][1]=j+1;
			}
		}
	}if(aa[1][0]==aa[0][0]){
		cout<<aa[2][0]<<' ';
		if(aa[2][1]==aa[0][1])cout<<aa[1][1];else cout<<aa[0][1];
	}
	else {
		cout<<aa[0][0]<<' ';
		if(aa[1][1]==aa[0][1])cout<<aa[2][1];else cout<<aa[1][1];
	}
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int aa[5][2];
string str;
using namespace std;
int main(){
	int n,m,k=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>str;
		for(int j=0;j<m;j++){
			if(str[j]=='*'){
				aa[k][0]=i;aa[k++][1]=j+1;
			}
		}
	}if(aa[1][0]==aa[0][0]){
		cout<<aa[2][0]<<' ';
		if(aa[2][1]==aa[0][1])cout<<aa[1][1];else cout<<aa[0][1];
	}
	else {
		cout<<aa[0][0]<<' ';
		if(aa[1][1]==aa[0][1])cout<<aa[2][1];else cout<<aa[1][1];
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define r return
#define TIME ios_base::sync_with_stdio( 0 );
using namespace std;

    const ll N = 1e3 + 1;
    const ll INF = 1e18 ;

ll n , m , l , k , x , y , z , cnt , ans , sum , mx , mn = INF ;
vector < ll > v ;
deque < ll > d ;
string s , t , T ;
map < char , ll > mp ;
char a [ N ] [ N ];
int main()
{
///34A
    TIME ;
    //freopen( "input.txt", "r" , stdin );
    //freopen( "output.txt", "w" , stdout );

    cin >> n >> m ;

    for ( int i = 1 ; i <= n ; i ++ ){
        for( int j = 1; j <= m ; j ++ ){
            cin >> a[ i ] [ j ];
        }
    }
    for ( int i = 1 ; i <= n ; i ++ ){
        for( int j = 1; j <= m ; j ++ ){
            if ( a[ i ] [ j ] == '*' )
            cnt ++ ;
        }
        if ( cnt == 1 )
        {
            for ( int j = 1; j <= m ; j ++ ){
                if ( a[ i ] [ j ] == '.' ){
                    for ( int k = 1; k <= n ; k ++ ) {
                        if ( a[ k ] [ j ] == '*' )
                           r cout << i << " " << j , 0;
                    }
                }
            }
        }
            cnt = 0 ;
    }
}


#include<bits/stdc++.h>

using namespace std;
/*
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
typedef long long ll ;
const ll mk = 100055;
const ll logn  = 29;
const ll mod = 1e9 + 7;

#define endl             "\n"
#define IOS              ios::sync_with_stdio(0); cin.tie(0);
#define fi               first
#define se               second
#define pii              pair<ll,ll>
#define mp               make_pair
#define pq               priority_queue<int, std::vector<int>, std::greater<int> >
#define rep(i, n)        for(int i = 0 ; i < n ; i++)
#define repf(i , n )     for(int i = 1; i <= n ; i++)
#define pb               push_back

int n, m ,q, num = 0;
char a[105][105];
vector<int> g[mk];
pii t[mk];

void init() {
    cin >> n >> m;
    repf(i , n) {
    	repf(j , m) {
    		cin >> a[i][j] ;
    	    if(a[i][j] == '*') t[++num] = {i , j};
		}
	}
}
signed main() {
	init();
	for(int i = 1; i <= 3; i++) {
		for(int j = i + 1; j <= 3; j++) {
			if(t[i].fi == t[j].fi) {
				int x = 6 - i - j ;
				if(t[i].se == t[x].se) swap(t[i] , t[j]);
			    int row = t[x].fi ;
			    int col = t[i].se;
			    cout << row << ' ' << col;
			    return 0;
			}
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
#define mxN 200005
#define inf 1000000000000000000
using namespace std;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const ll mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,m; cin >> n >> m;
    int row[105] = {}, col[105] = {};
    char x;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> x;
            if (x == '*') {
                row[i]++;
                col[j]++;
            }
        }
    }
    for (int i = 0; i < 100; i++) {
        if (row[i] == 1) n = i+1;
        if (col[i] == 1) m = i+1;
    }
    cout << n << " " << m << '\n';
}


#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#include <string>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
#define MAX 100000
typedef long long ll;
const ll MOD = 1e9;
using namespace std;

int main()
{
    SRK;
    int n,m;
    cin >> n >> m;
    string s[n];
    vector < pair< int, int> > vect;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        for (int j = 0; j < m; j++)
        {
            if (s[i][j] == '*')
            {
                vect.push_back({i+1,j+1});
            }
        }
    }
    sort(vect.begin(),vect.end());
    for (int i = 0; i < vect.size(); i++)
    {
        if (vect[i].first == vect[i + 1].first)
        {
            if (i == 1)
            {
                cout << vect[i - 1].first << " ";
                if (vect[i].second == vect[i - 1].second)
                {
                    cout << vect[i + 1].second;
                }
                else
                {
                    cout << vect[i].second;
                }
            }
            else
            {
                cout << vect[i + 2].first << " ";
                if (vect[i].second == vect[i + 2].second)
                {
                    cout << vect[i + 1].second;
                }
                else
                {
                    cout << vect[i].second;
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

int unique(int *a)
{
	int uni;

	if(a[0]==a[1])
		uni = a[2];
	else if(a[0]==a[2])
		uni = a[1];
	else
		uni = a[0];

	return uni;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n,m,r,c,index;

	cin >> n >> m;

	char a[n][m];
	int row[3], col[3];

	for(int i=0; i<n; ++i)
		for(int j=0; j<m; ++j)
			cin >> a[i][j];

	index = 0;

	for(int i=0; i<n; ++i)
		for(int j=0; j<m; ++j)
		{
			if(a[i][j]=='*')
			{
				row[index] = i;
				col[index] = j;
				index++;
			}
		}

	r = unique(row) + 1;
	c = unique(col) + 1;

	cout << r << " " << c << "\n";

	return 0;
}


#include <cstdlib>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
#include <functional>
using namespace std;

int prod_max_min_dig(int num)
{
	int dig;
	int max_dig = 0;
	int min_dig = 9;
	while (num > 0)
	{
		dig = num % 10;
		if (dig > max_dig)
			max_dig = dig;
		if (dig < min_dig)
			min_dig = dig;
		num /= 10;
	}
	return min_dig * max_dig;
}

int32_t main()
{
	int t;
	long long a, k, a2;
	cin >> t;
	while (t)
	{
		cin >> a >> k;
		for (int i = 1; i < k; i++)
		{
			a2 = a + prod_max_min_dig(a);
			if (a == a2)
			{
				break;
			}
			a = a2;
		}
		cout << a << endl;
		t--;
	}
	return 0;

}


#include <cstdlib>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
#include <functional>
using namespace std;

int prod_max_min_dig(int num)
{
	int dig;
	int max_dig = 0;
	int min_dig = 9;
	while (num > 0)
	{
		dig = num % 10;
		if (dig > max_dig)
			max_dig = dig;
		if (dig < min_dig)
			min_dig = dig;
		num /= 10;
	}
	return min_dig * max_dig;
}

int32_t main()
{
	int t, a, k;
	cin >> t;
	while (t)
	{
		cin >> a >> k;
		for (int i = 1; i < k; i++)
		{
			a += prod_max_min_dig(a);
		}
		cout << a << endl;
		t--;
	}
	return 0;

}


#include <cstdlib>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <tuple>
#include <functional>
using namespace std;

long long prod_max_min_dig(long long num)
{
	int dig;
	int max_dig = 0;
	int min_dig = 9;
	while (num > 0)
	{
		dig = num % 10;
		if (dig > max_dig)
			max_dig = dig;
		if (dig < min_dig)
			min_dig = dig;
		num /= 10;
	}
	return min_dig * max_dig;
}

int32_t main()
{
	int t;
	long long a, k, a2;
	cin >> t;
	while (t)
	{
		cin >> a >> k;
		for (int i = 1; i < k; i++)
		{
			a2 = a + prod_max_min_dig(a);
			if (a == a2)
			{
				break;
			}
			a = a2;
		}
		cout << a << endl;
		t--;
	}
	return 0;

}


#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int gcd(int a, int b) {
	if (b > a) {
		swap(a, b);
	}
	while (b > 0) {
		a %= b;
		swap(a, b);
	}
	return a;
}
int pow1(int a, int b) {
	int c = b;
	if (a == 0) {
		return 1;
	}
	a--;
	while (a > 0) {
		if (a % 2 == 0) {
			c *= c;
			a /= 2;
		}
		else {
			c *= b;
			a--;
		}
	}
	return c;
}

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long long n, k;
		cin >> n >> k;
		long long m1 = 10, m2 = -1;
		long long n1 = n;
		while (n1 > 0) {
			m1 = min(m1, (n1 % 10));
			m2 = max(m2, (n1 % 10));
			n1 /= 10;
		}
		k--;
		while (m1 * m2 != 0 && k > 0) {
			n += m1 * m2;
			n1 = n;
			m1 = 10, m2 = -1;
			while (n1 > 0) {
				m1 = min(m1, (n1 % 10));
				m2 = max(m2, (n1 % 10));
				n1 /= 10;
			}
			k--;
		}
		cout << n << '\n';
	}
}


#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int gcd(int a, int b) {
	if (b > a) {
		swap(a, b);
	}
	while (b > 0) {
		a %= b;
		swap(a, b);
	}
	return a;
}
int pow1(int a, int b) {
	int c = b;
	if (a == 0) {
		return 1;
	}
	a--;
	while (a > 0) {
		if (a % 2 == 0) {
			c *= c;
			a /= 2;
		}
		else {
			c *= b;
			a--;
		}
	}
	return c;
}

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long long n, k;
		string s;
		cin >> s >> k;
		n = stoi(s);
		int m1 = 10, m2 = -1;
		for (int j = 0; j < s.size(); j++) {
			m1 =min(m1, (int)(s[j] - '0'));
			m2 =max(m2, (int)(s[j] - '0'));
		}
		k--;
		while (m1 * m2 != 0 && k > 0) {
			n += m1 * m2;
			long long n1 = n;
			m1 = 10, m2 = -1;
			while (n1 > 0) {
				m1 = min(m1, (int)(n1 % 10));
				m2 = max(m2, (int)(n1 % 10));
				n1 /= 10;
			}
			k--;
		}
		cout << n << '\n';
	}
}


#include<iostream>
using namespace std;
int main()
{
	int t, a[10];
	cin >> t;
	for (int i = 0;i < t;i++)
	{
		int a1, k;
		cin >> a1 >> k;
		int ai = a1;
		for (int j = 1;j < k;j++)
		{
			int l[100];
			int x = 0;
			int a = ai;
			while (a != 0)
			{
				l[x] = a % 10;
				a = a / 10;
				x++;
			}
			int max = l[0];
			int min = l[0];
			for (int j = 0; j < x; j++)
			{
				if (min > l[j])
					min = l[j];
				if (max < l[j])
					max = l[j];
			}
			ai += min * max;
		}
		a[i] = ai;
	}

	for (int i = 0;i < t;i++)
		cout << a[i] << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	unsigned long long int t;
	cin >> t;
	for (unsigned long long int i = 0;i < t;i++)
	{
		unsigned long long int a1, k;
		cin >> a1 >> k;
		unsigned long long int ai = a1;
		for (unsigned long long int j = 1;j < k;j++)
		{
			unsigned long long int l[1000];
			unsigned long long int x = 0;
			unsigned long long int a = ai;
			while (a != 0)
			{
				l[x] = a % 10;
				a = a / 10;
				x++;
			}
			unsigned long long int max = l[0];
			unsigned long long int min = l[0];
			for (unsigned long long int j = 0; j < x; j++)
			{
				if (min != 0)
				{
					if (min > l[j])
						min = l[j];
				}
				if (max != 9)
				{
					if (max < l[j])
						max = l[j];
				}
				if (min == 0 && max == 9)
					break;
			}
			ai += min*max;
		}
		cout << ai << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	unsigned long long int t;
	cin >> t;
	for (unsigned long long int i = 0;i < t;i++)
	{
		unsigned long long int a1, k;
		cin >> a1 >> k;
		unsigned long long int ai = a1;
		for (unsigned long long int j = 1;j < k;j++)
		{
			unsigned long long int l[1000];
			unsigned long long int x = 0;
			unsigned long long int a = ai;
			unsigned long long int max = 0;
			unsigned long long int min = 10;
			while (a != 0)
			{
				l[x] = a % 10;
				a = a / 10;
				if (min != 0)
				{
					if (min > l[x])
						min = l[x];
				}
				if (max != 9)
				{
					if (max < l[x])
						max = l[x];
				}
				if (min == 0 && max == 9)
					break;
				x++;

			}
			ai += min*max;
		}
		cout << ai << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t, a[10];
	cin >> t;
	for (int i = 0;i < t;i++)
	{
		int a1, k;
		cin >> a1 >> k;
		int ai = a1;
		for (int j = 1;j < k;j++)
		{
			int l[100];
			int i = 0;
			int a = ai;
			while (a != 0)
			{
				l[i] = a % 10;
				a = a / 10;
				i++;
			}
			int max = l[0];
			int min = l[0];
			for (int j = 0; j < i; j++)
			{
				if (min > l[j])
					min = l[j];
				if (max < l[j])
					max = l[j];
			}
			ai += min * max;
		}
		a[i] = ai;
	}

	for (int i = 0;i < t;i++)
		cout << a[i] << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t, a[10];
	cin >> t;
	for (int i = 0;i < t;i++)
	{
		int a1, k;
		cin >> a1 >> k;
		int ai = a1;
		for (int j = 1;j < k;j++)
		{
			int l[100];
			int i = 0;
			int a = ai;
			while (a != 0)
			{
				l[i] = a % 10;
				a = a / 10;
				i++;
			}
			int max = l[0];
			int min = l[0];
			for (int j = 0; j < i; j++)
			{
				if (min > l[j])
					min = l[j];
				if (max < l[j])
					max = l[j];
			}
			ai += min * max;
		}
		cout << ai;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t, a[10];
	cin >> t;
	for (int i = 0;i < t;i++)
	{
		int a1, k;
		cin >> a1 >> k;
		int ai = a1;
		for (int j = 1;j < k;j++)
		{
			int l[100];
			int i = 0;
			int a = ai;
			while (a != 0)
			{
				l[i] = a % 10;
				a = a / 10;
				i++;
			}
			int max = l[0];
			int min = l[0];
			for (int j = 0; j < i; j++)
			{
				if (min > l[j])
					min = l[j];
				if (max < l[j])
					max = l[j];
			}
			ai += min * max;
		}
		a[i] = a[i];
	}

	for (int i = 0;i < t;i++)
		cout << a[i] << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	unsigned long long int t,i;
	cin >> t;
	for (i = 0;i < t;i++)
	{
		unsigned long long int a1, k,ai,j,a;
		cin >> a1 >> k;
		ai = a1;
		for (j = 1;j < k;j++)
		{
			a = ai;
			unsigned long long int max = 0;
			unsigned long long int min = 10;
			int f = 0;
			while (a != 0 && f==0)
			{
				if (min != 0)
				{
					if (min > a % 10)
						min = a % 10;
				}
				else break;
				if (max != 9)
				{
					if (max < a%10)
						max = a%10;
				}
				if (min == 0 && max == 9)
					f = 1;
				a = a / 10;
			}
			if (min == 0)
				break;
			ai += min * max;
		}
		cout << ai << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	unsigned long long int t, a[1000];
	cin >> t;
	for (unsigned long long int i = 0;i < t;i++)
	{
		unsigned long long int a1, k;
		cin >> a1 >> k;
		unsigned long long int ai = a1;
		for (unsigned long long int j = 1;j < k;j++)
		{
			unsigned long long int l[1000];
			unsigned long long int x = 0;
			unsigned long long int a = ai;
			while (a != 0)
			{
				l[x] = a % 10;
				a = a / 10;
				x++;
			}
			unsigned long long int max = l[0];
			unsigned long long int min = l[0];
			for (unsigned long long int j = 0; j < x; j++)
			{
				if (min != 0)
				{
					if (min > l[j])
						min = l[j];
				}
				if (max != 9)
				{
					if (max < l[j])
						max = l[j];
				}
				if (min == 0 && max == 9)
					break;
			}
			ai += min*max;
		}
		a[i] = ai;
	}

	for (unsigned long long int i = 0;i < t;i++)
		cout << a[i] << endl;
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int s[25],t;
void cal(long long c)
{
	t=0;
	while(c)
	{
		s[++t]=c%10;
		c/=10;
	}
	sort(s+1,s+1+t);
}
int main()
{
	int u;
	int i;
	long long a,k;
	scanf("%d",&u);
	while(u--)
	{
		scanf("%lld%lld",&a,&k);
		for(i=1;i<k;i++)
		{
			cal(a);
			a+=s[1]*s[t];
			if(!s[1])
			break;
		}
		printf("%lld\n",a);
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);

	int t;
	cin >> t;
	for (int test = 0; test < t; ++test) {
		int res = 0;
		long long n, k;
		cin >> n >> k;
		for (long long i = 1; i < k; ++i) {
			int mind = 10, maxd = 0;
			long long tmp = n;
			while (tmp) {
				mind = min<int>(mind, tmp % 10);
				maxd = max<int>(maxd, tmp % 10);
				tmp /= 10;
			}
			if (mind == 0) break;
			n = n + maxd*mind;
		}
		cout << n << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);

	int t;
	cin >> t;
	for (int test = 0; test < t; ++test) {
		int res = 0;
		long long n, k;
		cin >> n >> k;
		for (long long i = 1; i < k; ++i) {
			int mind = 10, maxd = 0;
			long long tmp = n;
			while (tmp) {
				mind = min(mind, (int)tmp % 10);
				maxd = max(maxd, (int)tmp % 10);
				tmp /= 10;
			}
			if (mind == 0) break;
			n = n + maxd*mind;
		}
		cout << n << endl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<deque>
#define LL long long int
#define module 1000000007
using namespace std;

int main()
{
    int t; cin >>t;
    while(t--)
    {
        LL n,k;
        cin >>n >>k;
        if(k==1) cout<<n<<endl;
        else
        {
            LL j=1;
            LL ans=n;
            while(j<k)
            {
                LL b=ans;
                int mi=10,mx=0;
                vector<int> v;
                while(ans>0)
                {
                    v.push_back(ans%10);
                    ans=ans/10;
                }
                for(int i=0;i<v.size();i++)
                {

                    if(mx<v[i]) mx=v[i];
                    if(mi>v[i]) mi=v[i];
                }
                j++;

                ans=b+mi*mx;
            }
            cout<<ans<<endl;
        }

    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<deque>
#define LL long long int
#define module 1000000007
using namespace std;

int main()
{
    int t; cin >>t;
    while(t--)
    {
        LL n,k;
        cin >>n >>k;
        if(k==1) cout<<n<<endl;
        else
        {
            LL j=1;
            LL ans=n;
            while(j<k)
            {
                LL b=ans;
                int mi=10,mx=0;
                vector<int> v;
                while(ans>0)
                {
                    v.push_back(ans%10);
                    ans=ans/10;
                }
                for(int i=0;i<v.size();i++)
                {

                    if(mx<v[i]) mx=v[i];
                    if(mi>v[i]) mi=v[i];
                }
                j++;
                ans=b+mi*mx;
                if(mi==0) break;
            }
            cout<<ans<<endl;
        }

    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		long long a, k;
		scanf("%lld%lld", &a, &k);
		for (long long i = 1; i < k; ++i)
		{
			long long tmp = a;
			int n = 9, x = 0;
			do
			{
				int r = tmp % 10;
				tmp /= 10;
				n = n <= r ? n : r;
				x = x >= r ? x : r;
			} while (tmp);
			if (n == 0)
			{
				break;
			}
			a += n * x;
		}
		printf("%lld\n", a);
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int a, k;
		scanf("%d%d", &a, &k);
		for (int i = 1; i < k; ++i)
		{
			int tmp = a;
			int n = 9, x = 0;
			do
			{
				int r = tmp % 10;
				tmp /= 10;
				n = n <= r ? n : r;
				x = x >= r ? x : r;
			} while (tmp);
			if (n == 0)
			{
				break;
			}
			a += n * x;
		}
		printf("%d\n", a);
	}
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <string>
#include <tuple>
#include <functional>
using namespace std;
typedef long long ll;
int ret_min(ll num){
	int arr[10] = {0,};
	while(num!=0){
		arr[num%10] = 1;
		num/=10;
	}
	for(int i = 0;i<10;i++)
		if(arr[i] == 1)
			return i;
}
int ret_max(ll num){
	int arr[10] = {0,};
	while(num!=0){
		arr[num%10] = 1;
		num/=10;
	}
	for(int i = 9;i>=0;i--)
		if(arr[i] == 1)
			return i;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		ll n,k;
		scanf("%lld %lld",&n,&k);
		k--;
		while(k--){
			int tmp = ret_min(n);
			tmp *= ret_max(n);
			if(tmp == 0)
				break;
			n+=tmp;
		}
		printf("%lld\n",n);
	}
}


#include<iostream>
#include<vector>

using namespace std;

#define ll long long int

int calVal(ll n){

    int maxVal = -1, minVal = 10;

    while(n > 0){
        int rem = n % 10;
        if(rem > maxVal){
            maxVal = rem;
        }
        if(rem < minVal){
            minVal = rem;
        }
        n /= 10;
    }

    return (maxVal) * (minVal);
}

int main(){

    int t;
    cin>>t;

    while(t-- > 0){

        ll n, k;
        cin>>n>>k;

        ll x = n;
        if(k != 1){
            int fac;
            while(k-- > 0){
                fac = calVal(x);
                if(fac == 0){
                    break;
                }
                x += fac;
            }
            x -= fac;
        }
        cout<<x<<endl;
    }

    return 0;
}


#include<iostream>
#include<vector>

using namespace std;

#define ll long long int

ll calVal(ll n, ll k){
    if(k == 1){
        return n;
    }

    ll ans = calVal(n, k - 1);

    int maxVal = -1, minVal = 10;
    ll temp = ans;

    while(temp > 0){
        int rem = temp % 10;
        if(rem > maxVal){
            maxVal = rem;
        }
        if(rem < minVal){
            minVal = rem;
        }
        temp /= 10;
    }

    return ans + (maxVal) * (minVal);
}

int main(){

    int t;
    cin>>t;

    while(t-- > 0){

        ll n, k;
        cin>>n>>k;

        ll ans = calVal(n, k);
        cout<<ans<<endl;
    }

    return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>
#include <queue>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        ll a,k,s,mx,mn,ans=1;
        cin>>a>>k;
        for(int i=0; i<k-1; i++){
            s=a;mn=a;mx=0;
            while(s>0){
                mx=max(mx,s%10);
                mn=min(mn,s%10);
                s/=10;
            }
            a=a+mn*mx;
            if(mn==0 || mx==0){
                cout << a << "\n";
                ans=-1;
                break;
            }
        }
        if(ans==1)
            cout << a << "\n";
    }
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>
#include <queue>
#define ll long long
#define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int a,k,s,mx,mn,ans=1;
        cin>>a>>k;
        for(int i=0; i<k-1; i++){
            s=a;mn=a;mx=0;
            while(s>0){
                mx=max(mx,s%10);
                mn=min(mn,s%10);
                s/=10;
            }
            a=a+mn*mx;
            if(mn==0 || mx==0){
                cout << a << "\n";
                ans=-1;
                break;
            }
        }
        if(ans==1)
            cout << a << "\n";
    }
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int t;
cin>>t;
long long a,k;
while(t--)
{
	cin>>a>>k;

	for(long long i=1;i<k;i++)
	{
		long long num=a;
		long long minn=9,maxn=0;
		while(num)
		{
			minn=min((num%10),minn);
			maxn=max((num%10),maxn);
			num=num/10;
		}
		a=a+minn*maxn;
		if(minn==0) break;
	}
	cout<<a<<endl;
}
}


#include <cmath>
#include <iostream>
using namespace std;
int b[19];int c[19];int d[19];
unsigned long long hic(unsigned long long n)
{
    unsigned long long x=n;
    int lon=x%10;
    int be =x%10;
    for(int i=0;i<log10(n);i++)
    {
        int m=x%10;
        if(m==0)
        {
            return n;
        }
        lon=max(lon,m);
        be=min(be,m);
        x=x/10;
    }
    n=n+lon*be;
    return n;
}
int main()
{
    unsigned int a;
    cin>>a;
    for(int t=1;t<=a;t++)
    {
        unsigned long long n;unsigned long long k;
        cin>>n>>k;
        for(int e=1;e<k;e++)
        {
            n=hic(n);
        }
        cout<<n<<endl;
    }
    return 0;
}


#include <cmath>
#include <iostream>
using namespace std;
int b[19];int c[19];int d[19];
unsigned long long hic(unsigned long long n)
{
    unsigned long long x=n;
    int lon=x%10;
    int be =x%10;
    for(int i=0;i<log10(n);i++)
    {
        int m=x%10;
        if(m==0)
        {
            return n;
        }
        if(lon<m)
        {
            lon=m;
        }
        if(be>m)
        {
            be=m;
        }
        x=x/10;
    }
    n=n+lon*be;
    return n;
}
int main()
{
    unsigned int a;
    cin>>a;
    for(int t=1;t<=a;t++)
    {
        unsigned long long n;unsigned long long k;
        cin>>n>>k;
        for(int e=1;e<k;e++)
        {
            n=hic(n);
        }
        cout<<n<<endl;
    }
    return 0;
}


#include <cmath>
#include <iostream>
using namespace std;
int b[19];int c[19];int d[19];
unsigned long long hic(unsigned long long n,unsigned long long k)
{
    if(k==1)
    {
        return n;
    }
    unsigned long long x=n;
    int lon=x%10;
    int be =x%10;
    for(int i=0;i<log10(n);i++)
    {
        int m=x%10;
        lon=max(lon,m);
        be=min(be,m);
        x=x/10;
    }
    if(lon*be==0)
        return hic(n,1);
    n=n+lon*be;
    return hic(n,k-1);
}

int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    unsigned int a;
    cin>>a;
    for(int t=1;t<=a;t++)
    {
        unsigned long long n;unsigned long long k;
        cin>>n>>k;
        cout<<hic(n,k)<<endl;
    }
    return 0;
}


#include <cmath>
#include <iostream>
using namespace std;
int b[19];int c[19];int d[19];
unsigned long long hic(unsigned long long n)
{
    unsigned long long x=n;
    int lon=x%10;
    int be =x%10;
    for(int i=0;i<log10(n);i++)
    {
        int m=x%10;
        if(m==0)
        {
            return n;
        }
        if(lon<m)
        {
            lon=m;
        }
        if(be>m)
        {
            be=m;
        }
        x=x/10;
    }
    n=n+lon*be;
    return n;
}
int main()
{
    unsigned int a;
    cin>>a;
    for(int t=1;t<=a;t++)
    {
        unsigned long long n;unsigned long long k;
        cin>>n>>k;
        for(int e=1;e<k;e++)
        {
            if(hic(n)==n) break;
            n=hic(n);
        }
        cout<<n<<endl;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>
#include <sstream>
#include <iterator>
using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

const int mod = 998244353;

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0)
		if (b & 1) {
			res = (long long)(res * 1ll * a);//% mod;
			--b;
		}
		else {
			a = (long long)(a * a);//% mod;
			b >>= 1;
		}
	return (long long)res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int q;
	cin >> q;
	while (q--)
	{
		long long n, k;
		cin >> n >> k;
		long long last = -1;
		for (int i = 1; i < k; i++)
		{
			vector<int>p;
			long long cnt = 10;
			while ((cnt / 10) <= n) {
				p.push_back((n % cnt) / (cnt / 10));
				cnt *= 10;
			}
			sort(p.begin(), p.end());
			int maxi = p[p.size() - 1];
			int mini = p[0];
			n += mini * maxi;
			if (n == last) break;
		}
		cout << n<< endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>
#include <sstream>
#include <iterator>
using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

const int mod = 998244353;

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0)
		if (b & 1) {
			res = (long long)(res * 1ll * a);//% mod;
			--b;
		}
		else {
			a = (long long)(a * a);//% mod;
			b >>= 1;
		}
	return (long long)res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int q;
	cin >> q;
	while (q--)
	{
		long long n, k;
		cin >> n >> k;
		long long last = -1;
		for (int i = 1; i < k; i++)
		{
			vector<int>p;
			long long cnt = 10;
			int maxi = -1;
			int mini = 1e9+60;
			while ((cnt / 10) <= n) {
				p.push_back((n % cnt) / (cnt / 10));
				maxi = max(maxi, p.back());
				mini = min(mini, p.back());
				cnt *= 10;
			}

			n += mini * maxi;
			if (n == last) break;
			last = n;
		}
		cout << n << '\n';
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>
#include <sstream>
#include <iterator>
using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

const int mod = 998244353;

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0)
		if (b & 1) {
			res = (long long)(res * 1ll * a);//% mod;
			--b;
		}
		else {
			a = (long long)(a * a);//% mod;
			b >>= 1;
		}
	return (long long)res;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int q;
	cin >> q;
	while (q--)
	{
		long long n, k;
		cin >> n >> k;
		long long last = -1;
		for (int i = 1; i < k; i++)
		{
			vector<int>p;
			unsigned long long cnt = 10;
			int maxi = -1;
			int mini = 1e9 + 60;
			while ((cnt / 10) <= n) {
				p.push_back((n % cnt) / (cnt / 10));
				maxi = max(maxi, p.back());
				mini = min(mini, p.back());
				if (p.size() == 18) {
					p.push_back(n / cnt);
					break;
				}
				cnt *= 10;
			}

			n += mini * maxi;
			if (n == last) break;
			last = n;
		}
		cout << n << '\n';
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int t = 0; cin >> t;
	while (t--)
	{
		long long a, K; cin >> a >> K;
		long long minD = 10, maxD = -1;
		long long minD0 = 10, maxD0 = -1;
		long long x = a;
		while (x > 1000)
		{
			if (x % 10 > maxD0) maxD0 = x % 10;
			if (x % 10 < minD0) minD0 = x % 10;
			x /= 10;
		}
		while (--K)
		{
			x = a % 1000;
			minD = minD0, maxD = maxD0;
			while (x > 0)
			{
				if (x % 10 > maxD) maxD = x % 10;
				if (x % 10 < minD) minD = x % 10;
				x /= 10;
			}
			if (minD == 0) break;
			a += minD * maxD;
		}
		cout << a << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int t = 0; cin >> t;
	while (t--)
	{
		long long a, K; cin >> a >> K;
		long long minD = 10, maxD = -1;
		long long minD0 = 10, maxD0 = -1;
		long long x = a;
		x /= 1000;
		while (x > 0)
		{
			if (x % 10 > maxD0) maxD0 = x % 10;
			if (x % 10 < minD0) minD0 = x % 10;
			x /= 10;
		}
		while (--K)
		{
			x = a % 1000;
			minD = minD0, maxD = maxD0;
			if (a > 999 && x < 100) minD = 0;
			while (x > 0)
			{
				if (x % 10 > maxD) maxD = x % 10;
				if (x % 10 < minD) minD = x % 10;
				x /= 10;
			}
			if (minD == 0) break;
			a += minD * maxD;
		}
		cout << a << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int t = 0; cin >> t;
	while (t--)
	{
		long long a, K; cin >> a >> K;
		int minD=10, maxD=-1;
		while (--K)
		{
			int x = a;
			minD = 10, maxD = -1;
			while (x > 0)
			{
				if (x % 10 > maxD) maxD = x % 10;
				if (x % 10 < minD) minD = x % 10;
				x /= 10;
			}
			if (minD == 0) break;
			a = a + minD * maxD;
		}
		cout << a << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int t = 0; cin >> t;
	while (t--)
	{
		long long a, K; cin >> a >> K;
		long long minD=10, maxD=-1;
		long long minD0 = 10, maxD0 = -1;
		long long x = a;
		while (x > 1000)
		{
			if (x % 10 > maxD0) maxD0 = x % 10;
			if (x % 10 < minD0) minD0 = x % 10;
			x /= 10;
		}
		long long xx = a % 1000;
		while (--K)
		{
			x = xx;
			minD = minD0, maxD = maxD0;
			while (x > 0)
			{
				if (x % 10 > maxD) maxD = x % 10;
				if (x % 10 < minD) minD = x % 10;
				x /= 10;
			}
			if (minD == 0 || x>999) break;
			a += minD * maxD;
			xx += minD * maxD;
		}
		cout << a << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p,int &mini,int &maxi) {
	int maxim=0;
	int minim = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < minim) minim = na;
		if (na > maxim) maxim = na;
		p /= 10;
	}
	maxi = maxim;
	mini = minim;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			int mini, maxi;
			num(n, mini,maxi);
			n+= mini*maxi ;
		}
		cout << n << endl;
	}
	//jopa
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p,int &mini,int &maxi) {
	int maxim=0;
	int minim = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < minim) minim = na;
		if (na > maxim) maxim = na;
		p /= 10;
	}
	maxi = maxim;
	mini = minim;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			int mini, maxi;
			num(n, mini,maxi);
			n+= mini*maxi ;
		}
		cout << n << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
int num(int p) {
	int mn, mx;
	mn = 10;
	mx = 0;
	while (p > 0) {
		int na = p % 10;
		mn = min(na, mn);
		mx = max(na, mn);
		p /= 10;
	}
	return mn * mx;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		k--;
		while (k--) {
			int ma = num(n);
			if (ma == 0) break;
			n += ma;

		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p, vector<int>&vec) {
	while (p > 0) {
		int na = p % 10;
		if(na!=0) vec.push_back(na);
		p /= 10;
	}
	if (vec.empty()) vec.push_back(0);
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			vector<int>vec;
			num(n, vec);
			int mini = *min_element(vec.begin(), vec.end());
			int maxi = *max_element(vec.begin(), vec.end());
			n+= mini*maxi ;
		}
		cout << n << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p,int &mini,int &maxi) {
	int maxim=0;
	int minim = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < minim) minim = na;
		if (na > maxim) maxim = na;
		p /= 10;
	}
	maxi = maxim;
	mini = minim;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			int mini, maxi;
			num(n, mini, maxi);
			if (mini == 0 || maxi == 0) break;
			else {
				n += mini * maxi;
			}
		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#define int long long
using namespace std;
int num(int p) {
	int mn, mx;
	mn = 10;
	mx = 0;
	while (p > 0) {
		int na = p % 10;
		mn = min(na, mn);
		mx = max(na, mx);
		p /= 10;
	}
	return mn * mx;
}
signed main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		k--;
		while (k--) {
			int ma = num(n);
			if (ma == 0) break;
			n += ma;

		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p,int &mini,int &maxi) {
	int maxim=0;
	int minim = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < minim) minim = na;
		if (na > maxim) maxim = na;
		p /= 10;
	}
	maxi = maxim;
	mini = minim;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			int mini, maxi;
			num(n, mini, maxi);
			if (mini == 0) break;
			else {
				n += mini * maxi;
			}
		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p,int &mini,int &maxi) {
	int maxim=0;
	int minim = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < minim) minim = na;
		if (na > maxim) maxim = na;
		p /= 10;
	}
	maxi = maxim;
	mini = minim;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			int mini, maxi;
			num(n, mini, maxi);
			if (mini == 0 || maxi == 0) break;
			else {
				n += mini * maxi;
			}
		}
		cout << n << endl;
		//jopa
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
int maxi(int p) {
	int maax = 0;
	while (p > 0) {
		int na = p % 10;
		if (na > maax) maax = na;
		p /= 10;
		if(maax ==9)
			break;

	}
	return maax;
}
int mini(int p) {
	int miin = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < miin) miin = na;
		p /= 10;
		if (miin == 1) break;
	}
	return miin;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			n = n + mini(n) * maxi(n);
		}
		cout << n << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
int num(int p) {
	int mn, mx;
	mn = 10;
	mx = 0;
	while (p > 0) {
		int na = p % 10;
		if (na < mn) mn = na;
		if (na > mx) mx = na;
		p /= 10;
	}
	return mn * mx;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		k--;
		while (k--) {
			int ma = num(n);
			if (ma == 0) break;
			n += ma;

		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
int num(int p) {
	int mn, mx;
	mn = 10;
	mx = 0;
	while (p > 0) {
		int na = p % 10;
		mn = min(na, mn);
		mx = max(na, mx);
		p /= 10;
	}
	return mn * mx;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		k--;
		while (k--) {
			int ma = num(n);
			if (ma == 0) break;
			n += ma;

		}
		cout << n << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
void num(int p, vector<int>&vec) {
	while (p > 0) {
		int na = p % 10;
		if(na!=0) vec.push_back(na);
		p /= 10;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			vector<int>vec;
			num(n, vec);
			int mini = *min_element(vec.begin(), vec.end());
			int maxi = *max_element(vec.begin(), vec.end());
			n = n + mini*maxi ;
		}
		cout << n << endl;
	}
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <set>
using namespace std;
int maxi(int p) {
	int maax = 0;
	while (p > 0) {
		int na = p % 10;
		if (na > maax) maax = na;
		p /= 10;
	}
	return maax;
}
int mini(int p) {
	int miin = 10;
	while (p > 0) {
		int na = p % 10;
		if (na < miin) miin = na;
		p /= 10;
	}
	return miin;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		for (int i = 0; i < k-1; i++) {
			n = n + mini(n) * maxi(n);
		}
		cout << n << endl;
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <tuple>
#include <array>
#include <numeric>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <queue>
#include <cstring>
#include <stack>
#include <numeric>
#include <cstdio>

//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int N = 300005;
int a[N], b[N], id[N], dp[N];
int n;

int main()
{
	int t;
	cin >> t;

	while (t--)
	{
		ll n, k;
		cin >> n >> k;

		for (int i = 1; i < k; ++i)
		{
			ll lo = n % 10;
			ll hi = n % 10;

			ll x = n;
			while (x > 0)
			{
				lo = min(lo, x % 10);
				hi = max(hi, x % 10);
				x /= 10;
			}

			if (lo == 0) break;
			n = n + lo * hi;
		}
		cout << n << endl;
	}

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <tuple>
#include <array>
#include <numeric>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <queue>
#include <cstring>
#include <stack>
#include <numeric>
#include <cstdio>

//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int N = 300005;
int a[N], b[N], id[N], dp[N];
int n;

int main()
{
	int t;
	cin >> t;

	while (t--)
	{
		ll n, k;
		cin >> n >> k;

		for (int i = 1; i < k; ++i)
		{
			ll lo = n % 10;
			ll hi = n % 10;

			ll x = n;
			while (x > 0)
			{
				lo = min(lo, x % 10);
				hi = max(hi, x % 10);
				x /= 10;
			}

			n = n + lo * hi;
		}
		cout << n << endl;
	}

}


//name wzq
//内容
//文件名
#include<iostream>
#include<cstdio>
using namespace std;
int Max(int n)
{
 int q=n%10;
 while(n)
 {
  if(q<n%10)
  {
   q=n%10;
  }
  n=n/10;
 }
 return q;
}
int Min(int n)
{
 int w=n%10;
 while(n)
 {
  if(w>n%10)
  {
   w=n%10;
  }
  n=n/10;
 }
 return w;
}
int ans(int n)
{
 return n+Max(n)*Min(n);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a,k;
		scanf("%d%d",&a,&k);
		int i;
		for(i=1;i<k;i++)
		{
			a=ans(a);
		}
		printf("%d\n",a);
	}
}


//name wzq
//内容
//文件名
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a1,k;
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>a1>>k;
		k-=1;
		while(k--)
		{
			long long  x=a1;
			long long mx=-1;long long mi=100;
			while(x)
			{
				mx=max(mx,x%10);
				mi=min(mi,x%10);
				x/=10;
			}
			if(mx==0||mi==0) break;
			a1+=1ll*mx*mi;
		}
		cout<<a1<<endl;

	}
 }


//name wzq
//内容
//文件名
#include<iostream>
using namespace std;
int Max(int n)
{
 int q=n%10;
 while(n)
 {
  if(q<n%10)
  {
   q=n%10;
  }
  n=n/10;
 }
 return q;
}
int Min(int n)
{
 int w=n%10;
 while(n)
 {
  if(w>n%10)
  {
   w=n%10;
  }
  n=n/10;
 }
 return w;
}
int ans(int n)
{
 return n+Max(n)*Min(n);
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,k;
		cin>>a>>k;
		int i;
		for(i=1;i<k;i++)
		{
			a=ans(a);
		}
		cout<<a<<endl;
	}
}


//name wzq
//内容
//文件名
#include<iostream>
#include<cstdio>
using namespace std;
long long a1,k;
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>a1>>k;
		k-=1;
		while(k--)
		{
			long long  x=a1;
			long long mx=-1;long long mi=100;
			while(x)
			{
				mx=max(mx,x%10);
				mi=min(mi,x%10);
				x/=10;
			}
			if(mx==0||mi==0) break;
			a1+=1ll*mx*mi;
		}
		cout<<a1<<endl;

	}
 }


#include <stdio.h>
#include<iostream>
#include<deque>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include <functional>
#include<iomanip>
#include<time.h>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
//#define PI acos(-1)
using namespace std;
const ll maxn = 1e5 + 10;

vector<int>v;
void Func(ll int a,ll int k)
{
	v.clear(); int c = 1;
	if (k == 0)cout<<a<<endl;
	else
	{
		//cout << "第K次" << k << endl;
		string s = to_string(a);
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == '0') { cout << a << endl; c = 0; break; }
			v.push_back((int)s[i] - 48);
		}
		//for (auto x : v)cout << x << endl;
		a+=*max_element(v.begin(), v.end()) **min_element(v.begin(), v.end());
		k--;
		if (c)Func(a, k);
	}
}

int t;

int main()
{
	cin >> t;
	while (t--)
	{
		ll int a;ll int  k;
		cin >> a >> k;
		Func(a, k-1);
	}
}


#include <stdio.h>
#include<iostream>
#include<deque>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include <functional>
#include<iomanip>
#include<time.h>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
//#define PI acos(-1)
using namespace std;
const ll maxn = 1e5 + 10;

vector<int>v;
void Func(ll int a, int k)
{
	v.clear();
	if (k == 0)cout<<a<<endl;
	else
	{
		//cout << "第K次" << k << endl;
		string s = to_string(a);
		for (int i = 0; i < s.length(); i++)
		{
			v.push_back((int)s[i] - 48);
		}
		//for (auto x : v)cout << x << endl;
		a+=*max_element(v.begin(), v.end()) **min_element(v.begin(), v.end());
		k--;
		Func(a, k);
	}
}

int t;

int main()
{
	cin >> t;
	while (t--)
	{
		ll int a;ll int  k;
		cin >> a >> k;
		Func(a, k-1);
	}
}


#include <stdio.h>
#include<iostream>
#include<deque>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include <functional>
#include<iomanip>
#include<time.h>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
//#define PI acos(-1)
using namespace std;
const ll maxn = 1e5 + 10;

vector<int>v;
void Func(ll int a, int k)
{
	v.clear();
	if (k == 0)cout<<a<<endl;
	else
	{
		//cout << "第K次" << k << endl;
		string s = to_string(a);
		for (int i = 0; i < s.length(); i++)
		{
			v.push_back((int)s[i] - 48);
		}
		//for (auto x : v)cout << x << endl;
		a+=*max_element(v.begin(), v.end()) **min_element(v.begin(), v.end());
		k--;
		Func(a, k);
	}
}

int t;

int main()
{
	cin >> t;
	while (t--)
	{
		ll int a;int  k;
		cin >> a >> k;
		Func(a, k-1);
	}
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <queue>
#include <iostream>
using namespace std;

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define repj1(n) for(int j=1;j<n;++j)
int _min(int a, int b) { return a <= b ? a : b; }
ll _min(ll a, ll b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
ll _max(ll a, ll b) { return a >= b ? a : b; }
void zero(int* data, int n) { memset(data, 0, sizeof(int) * n); }
void zero(ll* data, int n) { memset(data, 0, sizeof(ll) * n); }
void zero(unsigned long long* data, int n) { memset(data, 0, sizeof(unsigned long long) * n); }
void zero(char* data, int n) { memset(data, 0, sizeof(char) * n); }
char readc() { char var; fscanf(_fin, "%c", &var); return var; }
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
double readlf() { double var; fscanf(_fin, "%lf", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize)
{
	for (;;) { if (fgets(str, maxsize, _fin) == NULL) break; if (str[0] != '\n' && str[0] != '\r') break; }
	int slen = strlen(str); if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writeulln(var) fprintf(_fout,"%llu\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define sort(data,n) std::sort(data,data+n)
//#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b) //what the hell is this...
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return (a / g) * b; }
void reverse(char* data, int n) { int k = n >> 1; repi(k) { char tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
void reverse(ll* data, int n) { int k = n >> 1; repi(k) { ll tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b)\
{\
	name* a = (name*)_a;name* b = (name*)_b;\
	if (a->x < b->x) return -1;\
	else\
	{\
		if (a->x == b->x)\
		{\
			if (a->y == b->y) return 0;\
			if (a->y < b->y) return -1;\
			else return 1;\
		}\
		else\
		{\
			return 1;\
		}\
	}\
}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)
	_Pair(double,Pairlf)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

ll expmod(ll x, ll n, ll m) {
	ll ans = 1;
	for (; n;) {
		if (n & 1) ans = (ans * x) % m;
		x = (x * x) % m;
		n >>= 1;
	}
	return ans;
}

ll combmod(ll n, ll k, ll m) {
	ll ret = 1;
	ll div = 1;
	for (ll i = 0; i < k; ++i) {
		ret = (ret * (n - i) % m) % m;
		div = (div * (i + 1)) % m;
	}
	div = expmod(div, m - 2, m) % m;
	return (ret * div) % m;
}

int next_perm(int* data, int n)
{
	//find first i,i+1 where d[i]<d[i+1]
	int rootidx = -1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (data[i] < data[i + 1])
		{
			rootidx = i;
			break;
		}
	}

	if (rootidx == -1) return 0;

	int ceilingidx = rootidx + 1;
	//find smallest d[x] after d[rooti] where d[x]>d[rooti]
	for (int i = rootidx + 2; i < n; ++i)
	{
		if (data[i] > data[rootidx] && data[i] < data[ceilingidx])
		{
			ceilingidx = i;
		}
	}

	swap(int, data[rootidx], data[ceilingidx]);
	sort(&data[rootidx + 1], n - rootidx - 1);
	return 1;
}
int count_digits(ll a)
{
	int k = 0;
	for (;;)
	{
		if (a == 0)break;
		k++;
		a /= 10;
	}
	return k;
}

/*
use only when val EXISTS in data
*/
int bs_exists(int* data, int n, int val)
{
	int left = 0;
	int right = n - 1;
	for (; left < right;)
	{
		int mid = (left + right + 1) >> 1;
		if (data[mid] <= val) left = mid;
		else right = mid - 1;
	}
	return right;
}

ll simple_factorial(int x)
{
	ll f = 1.0;
	repi(x)
	{
		f *= (i + 1);
	}
	return f;
}

unsigned long long djb2(char* data, int n)
{
	unsigned long long h = 5381;
	for (int i = 0; i < n; ++i) h = (h << 5) + h + data[i];
	return h;
}

struct Hashcount
{
	int* count;
	unsigned long long* keys;
	int size_bits;
};
void init(Hashcount* h, int size_bits)
{
	h->size_bits = size_bits;
	int size = 1 << h->size_bits;
	h->count = (int*)malloc(sizeof(int) * size);
	zero(h->count, size);
	h->keys = (unsigned long long*)malloc(sizeof(unsigned long long) * size);
	zero(h->keys, size);
}

int set(Hashcount* h, unsigned long long key)
{
	//knuth's golden ratio multiplicative hashing for 64-bit keys
	int index = (key * 2654435761) >> (64 - h->size_bits);
	int size = 1 << h->size_bits;
	for (int i = 0; i < size; i++)
	{
		if (h->keys[index] == key) //if key exists, overwrite data
		{
			h->count[index]++;
			return index;
		}

		if (h->keys[index] == 0) //empty spot
		{
			h->count[index] = 1;
			h->keys[index] = key;
			return index;
		}

		index++;
		index &= size - 1;
	}

	return -1;//return invalid index if data was not placed. this could be used as an indicator to resize.
}

int get(Hashcount* h, unsigned long long key)
{
	int index = (key * 2654435761) >> (64 - h->size_bits);
	int size = 1 << h->size_bits;
	for (int i = 0; i < size; i++)
	{
		if (h->keys[index] == key)//found original key
		{
			return h->count[index];
		}

		if (h->keys[index] == 0) return 0;//if you see a zero,key was never there

		index++;
		index &= size - 1;
	}
	return 0;
}
//not sure if this works
int sub(Hashcount* h, unsigned long long key)
{
	int index = (key * 2654435761) >> (64 - h->size_bits);
	int size = 1 << h->size_bits;
	for (int i = 0; i < size; i++)
	{
		if (h->keys[index] == key)//found original key
		{
			--h->count[index];
			if (h->count[index] < 0) h->count[index] = 0;
			return h->count[index];
		}

		if (h->keys[index] == 0) return 0;//if you see a zero,key was never there

		index++;
		index &= size - 1;
	}
	return 0;
}

const ll MOD  = 1e9 + 7;
/*
//proper binary search???
//tested on 1 problem it works!!!!!!!
int left = 0;
int right = n-1;
for (;;)
{
	if (left >= right)break;
	int mid = (left + right) >> 1;
	if (x <= a[mid]) right = mid;
	else left = mid+1;
}

printf("%d %d\n",right, a[right]);
*/

//------------------------------------------

//------------

int main()
{

	RUN_LOCAL("input.txt");
	int t = readi();
	rep(_t, t)
	{
		ll a = readll();
		ll k = readll();
		repi(k-1)
		{
			ll x = a;
			int minx = a % 10;
			int maxx = minx;
			for (; x != 0;)
			{
				ll r = x % 10;
				if (r > maxx)maxx = r;
				if (r < minx)minx = r;
				x /= 10;
			}

			a += minx * maxx;

			if (minx == 0) break;

		}
		printf("%lld\n", a);

	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int min(long long n) {
	int ans = 9;
	while (n >= 10 && ans > 1) {
		if (ans > n % 10) ans = n % 10;
		n /= 10;
	}
	if (n < ans) ans = n;
	return ans;
}

int max(long long n) {
	int ans = 0;
	while (n >= 10 && ans < 9) {
		if (ans < n % 10) ans = n % 10;
		n /= 10;
	}
	if (n > ans && ans < 9) ans = n;
	return ans;
}

void a() {
	long long a1, k;
	cin >> a1 >> k;
	for (k; k > 1; k--) {
		int n1 = min(a1), n2 = max(a1);
		a1 += (n1 * n2);
	}
	cout << a1 << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) a();
}


#include <iostream>
#include <vector>
using namespace std;

int min(long long n) {
	int ans = 9;
	while (n >= 10 && ans > 1) {
		if (ans > n % 10 && n % 10 != 0) ans = n % 10;
		n /= 10;
	}
	if (n < ans) ans = n;
	return ans;
}

int max(long long n) {
	int ans = 1;
	while (n >= 10 && ans < 9) {
		if (ans < n % 10) ans = n % 10;
		n /= 10;
	}
	if (n > ans && ans < 9) ans = n;
	return ans;
}

void a() {
	long long a1, k;
	cin >> a1 >> k;
	for (k; k > 1; k--) {
		int n1 = min(a1), n2 = max(a1);
		a1 += (n1 * n2);
	}
	cout << a1 << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) a();
}


#include <iostream>
#include <vector>
using namespace std;

int min(long long n) {
	int ans = 9;
	while (n >= 10 && ans != 0) {
		if (ans > n % 10) ans = n % 10;
		n /= 10;
	}
	if (n < ans) ans = n;
	return ans;
}

int max(long long n) {
	int ans = 0;
	while (n >= 10 && ans != 9) {
		if (ans < n % 10) ans = n % 10;
		n /= 10;
	}
	if (n > ans && ans < 9) ans = n;
	return ans;
}

void a() {
	long long a1, k;
	cin >> a1 >> k;
	for (k; k > 1; k--) {
		int n1 = min(a1), n2 = max(a1);
		if (n1 * n2 == 0)break;
		a1 += (n1 * n2);
	}
	cout << a1 << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) a();
}


#include <iostream>
#include <vector>
using namespace std;

int min(long long n) {
	int ans = 9;
	while (n >= 10 && ans > 0) {
		if (ans > n % 10) ans = n % 10;
		n /= 10;
	}
	if (n < ans) ans = n;
	return ans;
}

int max(long long n) {
	int ans = 0;
	while (n >= 10 && ans < 9) {
		if (ans < n % 10) ans = n % 10;
		n /= 10;
	}
	if (n > ans && ans < 9) ans = n;
	return ans;
}

void a() {
	long long a1, k;
	cin >> a1 >> k;
	for (k; k > 1; k--) {
		int n1 = min(a1), n2 = max(a1);
		a1 += (n1 * n2);
	}
	cout << a1 << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) a();
}


#include <iostream>
#include <vector>
using namespace std;

int min(long long n) {
	int ans = 9;
	while (n >= 10 && ans > 1) {
		if (ans > n % 10) ans = n % 10;
		n /= 10;
	}
	if (n < ans) ans = n;
	return ans;
}

int max(long long n) {
	int ans = 1;
	while (n >= 10 && ans < 9) {
		if (ans < n % 10) ans = n % 10;
		n /= 10;
	}
	if (n > ans && ans < 9) ans = n;
	return ans;
}

void a() {
	long long a1, k;
	cin >> a1 >> k;
	for (k; k > 1; k--) {
		int n1 = min(a1), n2 = max(a1);
		a1 += (n1 * n2);
	}
	cout << a1 << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) a();
}


#include <iostream>
#include <math.h>

using namespace std;

typedef long long ll;

int main(){

    ll T;
    cin>>T;
    while(T--){
       ll a1, k;
       cin>>a1;
       cin>>k;

       k -= 1;
       while(k--){
       	  ll max = INT64_MIN, min = INT64_MAX;
       	  ll temp = a1;
       	  while(temp){
             max = (temp%10 > max) ?temp%10 :max ;
             min = (temp%10 < min) ?temp%10 :min ;
             temp /= 10;
       	  }
       	  if(min == 0)
       	  	break;

       	  a1 += max*min ;
       }

       cout<<a1<<"\n";
    }
	return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
#define ff first
#define ss second
#define sf ss.ff
#define tt ss.ss
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf ((ll)1<<60)
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#define pi acos(-1)
#define esp 1e-10
#define pb push_back

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef pair<double,double> dd;
typedef pair<double,dd> ddd;

/*
 *Use abbreviation:
 *dsu ->Disjoint Set Union
 *bit ->Binary Indexed Tree
 *math ->Mathematical Functions(gcd,fact,bigMod,ncr)
 *test ->For test cases
 */

ll n,a,k;

ll mn(ll a)
{
    if(a==0)
        return inf;
    return min(a%10,mn(a/10));
}

ll mx(ll a)
{
    if(a==0)
        return 0;
    return max(a%10,mx(a/10));
}

ll nxt(ll a)
{
    return a+mn(a)*mx(a);
}

int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>a>>k;
        while(--k&&mn(a))
            a=nxt(a);
        cout<<a<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#define ULL unsigned long long

using namespace std;

ULL MinMaxMult(ULL x);

int main()
{
    ULL t,K,an;

    cin>>t;

    for(ULL i=0;i<t;i++)
    {
        cin>>an>>K;
        //an = a1;
        for(ULL j=2;j<=K;j++)
        {
            an = an + MinMaxMult(an);
        }
        cout<<an<<endl;
    }

    return 0;
}

ULL MinMaxMult(ULL x)
{
    int max_Dig = 0,cur_Dig,min_Dig = 9;
    while((x>0)&&(min_Dig > 0))
    {
        cur_Dig = x%10;
        x /= 10;
        max_Dig = max(cur_Dig,max_Dig);
        min_Dig = min(cur_Dig,min_Dig);
    }

    return max_Dig*min_Dig;
}


#include <iostream>
#include <algorithm>
#define ULL unsigned long long

using namespace std;

int MinMaxMult(ULL x);

int main()
{
    ULL t,K,an;
    int dx;

    cin>>t;

    for(ULL i=0;i<t;i++)
    {
        cin>>an>>K;
        //an = a1;
        for(ULL j=2;j<=K;j++)
        {
            dx = MinMaxMult(an);
            an = an + dx;
            if(dx == 0)
                break;
        }
        cout<<an<<endl;
    }

    return 0;
}

int MinMaxMult(ULL x)
{
    int max_Dig = 0,cur_Dig,min_Dig = 9;
    while((x>0)&&(min_Dig > 0))
    {
        cur_Dig = x%10;
        x /= 10;
        max_Dig = max(cur_Dig,max_Dig);
        min_Dig = min(cur_Dig,min_Dig);
    }

    return max_Dig*min_Dig;
}


#include <iostream>
#define ULL unsigned long long

using namespace std;

ULL MinMaxMult(ULL x);

int main()
{
    ULL t,K,an;

    cin>>t;

    for(ULL i=0;i<t;i++)
    {
        cin>>an>>K;
        //an = a1;
        for(ULL j=2;j<=K;j++)
        {
            an = an + MinMaxMult(an);
        }
        cout<<an<<endl;
    }

    return 0;
}

ULL MinMaxMult(ULL x)
{
    int max_Dig = 0,cur_Dig,min_Dig = 9;
    while((x>0)&&(min_Dig > 0))
    {
        cur_Dig = x%10;
        x /= 10;
        max_Dig = max(cur_Dig,max_Dig);
        min_Dig = min(cur_Dig,min_Dig);
    }

    return max_Dig*min_Dig;
}


#include <iostream>

using namespace std;

int MaxDig(int x);
int MinDig(int x);

int main()
{
    unsigned long long t,a1,K,an;

    cin>>t;

    for(int i=0;i<t;i++)
    {
        cin>>a1>>K;
        an = a1;
        for(int j=2;j<=K;j++)
        {
            an = an + MinDig(an)*MaxDig(an);
        }
        cout<<an<<endl;
    }

    return 0;
}

int MaxDig(int x)
{
    int max_Dig = 0,cur_Dig;
    while((x>0)&&(max_Dig != 9))
    {
        cur_Dig = x%10;
        x /= 10;
        if(cur_Dig>max_Dig)
            max_Dig = cur_Dig;
    }

    return max_Dig;
}

int MinDig(int x)
{
    int min_Dig = 9,cur_Dig;
    while((x>0)&&(min_Dig != 0))
    {
        cur_Dig = x%10;
        x /= 10;
        if(cur_Dig<min_Dig)
            min_Dig = cur_Dig;
    }

    return min_Dig;
}


#include <iostream>
#include <cmath>
#define ULL unsigned long long

using namespace std;

ULL MinMaxMult(ULL x);

int main()
{
    ULL t,K,an;

    cin>>t;

    for(ULL i=0;i<t;i++)
    {
        cin>>an>>K;
        //an = a1;
        for(ULL j=2;j<=K;j++)
        {
            an = an + MinMaxMult(an);
        }
        cout<<an<<endl;
    }

    return 0;
}

ULL MinMaxMult(ULL x)
{
    int max_Dig = 0,cur_Dig,min_Dig = 9;
    while((x>0)&&(min_Dig > 0))
    {
        cur_Dig = x%10;
        x /= 10;
        max_Dig = max(cur_Dig,max_Dig);
        min_Dig = min(cur_Dig,min_Dig);
    }

    return max_Dig*min_Dig;
}


#include <iostream>
#define ULL unsigned long long

using namespace std;

int MaxDig(ULL x);
int MinDig(ULL x);

int main()
{
    ULL t,K,an;

    cin>>t;

    for(ULL i=0;i<t;i++)
    {
        cin>>an>>K;
        //an = a1;
        for(ULL j=2;j<=K;j++)
        {
            an = an + MinDig(an)*MaxDig(an);
        }
        cout<<an<<endl;
    }

    return 0;
}

int MaxDig(ULL x)
{
    int max_Dig = 0,cur_Dig;
    while((x>0)&&(max_Dig < 9))
    {
        cur_Dig = x%10;
        x /= 10;
        if(cur_Dig > max_Dig)
            max_Dig = cur_Dig;
    }

    return max_Dig;
}

int MinDig(ULL x)
{
    int min_Dig = 9,cur_Dig;
    while((x>0)&&(min_Dig > 0))
    {
        cur_Dig = x%10;
        x /= 10;
        if(cur_Dig < min_Dig)
            min_Dig = cur_Dig;
    }

    return min_Dig;
}


// Author   : tik-tok
// Language : C++
// ********************
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <cmath>
#include <bitset>
#include <string>
#include <stdlib.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define readFile  freopen("in.txt","r",stdin)
#define writeFile freopen("out.txt","w",stdout)
#define fastIO ios::sync_with_stdio(0)
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS

ll getMinMaxProd(ll x) {
	ll mn = 9, mx = 0;
	while (x > 0) {
		ll dig = x % 10;
		x = x / 10;
		mn = min(mn, dig);
		mx = max(mx, dig);
	}
	return mn * mx;
}

int main() {

#ifndef ONLINE_JUDGE
	readFile;
	//writeFile;

#endif;

	fastIO;
	int t;	cin >> t;
	while (t--) {
		ll x, k;
		cin >> x >> k;
		while (--k) {
			int v = getMinMaxProd(x);
			if (v == 0)	break;
			x += v;
		}
		cout << x << endl;
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void Digits(int n,int &x,int &y)
{
	int largest = 0;
	int smallest = 9;

	while (n) {
		int r = n % 10;

		largest = max(r, largest);

		smallest = min(r, smallest);

		n = n / 10;
	}
	x=largest;
	y=smallest;
}
int  main()
{
	int size;
	cin>>size;
	while(size>0)
	{
		int a,k;
		cin>>a>>k;
		int x,y;
		while(k>1){
			Digits(a,x,y);
			a=a+x*y;
			k--;
		}
		cout<<a<<endl;
		size--;
	}

//	system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void Digits(long long  n,int  &x,int  &y)
{
	int largest = 0;
	int  smallest = 9;

	while (n) {
		int  r = n % 10;

		largest = max(r, largest);

		smallest = min(r, smallest);

		n = n / 10;
	}
	x=largest;
	y=smallest;
}
int   main()
{
	int  size;
	cin>>size;
	while(size>0)
	{
		long long  a,k;
		cin>>a>>k;
		int  x,y;
		while(k>1){
			Digits(a,x,y);
			a=a+x*y;
			k--;
		}
		cout<<a<<endl;
		size--;
	}

//	system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void Digits(long long  n,long long  &x,long long  &y)
{
	long long  largest = 0;
	long long  smallest = 9;

	while (n) {
		long long  r = n % 10;

		largest = max(r, largest);

		smallest = min(r, smallest);

		n = n / 10;
	}
	x=largest;
	y=smallest;
}
int   main()
{
	long long  size;
	cin>>size;
	while(size>0)
	{
		long long  a,k;
		cin>>a>>k;
		long long  x,y;
		while(k>1){
			Digits(a,x,y);
			a=a+x*y;
			k--;
		}
		cout<<a<<endl;
		size--;
	}

//	system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
void Digits(long long  n,int  &x,int  &y)
{
	int largest = 0;
	int  smallest = 9;

	while (n) {
		int  r = n % 10;

		largest = max(r, largest);

		smallest = min(r, smallest);

		n = n / 10;
	}
	x=largest;
	y=smallest;
}
int   main()
{
	int  size;
	cin>>size;
	while(size>0)
	{
		long long  a,k;
		cin>>a>>k;
		int  x,y;
		while(k>1){
			Digits(a,x,y);
			if(y==0)
				break;
			a=a+x*y;
			k--;
		}
		cout<<a<<endl;
		size--;
	}

//	system("pause");
	return 0;

}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
void Digits(int n,int &x,int &y)
{
	int largest = 0;
	int smallest = 9;

	while (n) {
		int r = n % 10;

		largest = max(r, largest);

		smallest = min(r, smallest);

		n = n / 10;
	}
	x=largest;
	y=smallest;
}
int  main()
{
	int size;
	cin>>size;
	while(size>0)
	{
		int a,k;
		cin>>a>>k;
		int x,y;
		while(k>1){
			Digits(a,x,y);
			a=a+x*y;
			k--;
		}
		cout<<a<<endl;
		size--;
	}

//	system("pause");
	return 0;

}


#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
int b[25],bn;
void f(LL x){//ȡ��ʮ�����ϸ���λ�õ���
	bn=0;
	while(x){
		b[++bn]=x%10;
		x/=10;
	}
	sort(b+1,b+1+bn);//��ȡ����������С��������
}
int main(){
	int t,i;
	LL k,a;
	scanf("%d",&t);
	while(t--){
		scanf("%lld%lld",&a,&k);
		for(i=1;i<k;i++){
			f(a);a+=b[1]*b[bn];//������Ĺ�ʽ���м���
			if(!b[1])break;//�ҵ���ȡ����������Сֵ��0�����
		}
		printf("%lld\n",a);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int b[25],c;
void f(long long x){
	c=0;
    while(x){
    	b[c++]=x%10;
    	x=x/10;
	}
	sort(b,b+c);
}

int main(){
	int t;
	scanf("%lld",&t);
	while(t--){
		long long a,k;
		scanf("%lld%lld",&a,&k);
		for(int i=1;i<k;i++){
			f(a);
			a+=b[0]*b[c-1];
			if(!b[0]) break;
		}
		printf("%lld\n",a);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int b[25],c;
void f(long long x){
	c=0;
    while(x){
    	b[c++]=x%10;
    	x=x/10;
	}
	sort(b,b+c);
}

int main(){
	int t;
	scanf("%lld",&t);
	while(t--){
		long long a,k;
		scanf("%lld%lld",&a,&k);
		for(int i=1;i<=k;i++){
			f(a);
			a+=b[0]*b[c-1];
			if(!b[0]) break;
		}
		printf("%d\n",a);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int b[25],c;
void f(long long x){
	c=0;
    while(x){
    	b[c++]=x%10;
    	x=x/10;
	}
	sort(b,b+c);
}

int main(){
	int t;
	scanf("%lld",&t);
	while(t--){
		long long a,k;
		scanf("%lld%lld",&a,&k);
		for(int i=1;i<k;i++){
			f(a);
			a+=b[0]*b[c-1];
			if(!b[0]) break;
		}
		printf("%d\n",a);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    long long t; cin >> t;
    while (t--) {
        long long n; cin >> n; long long k; cin >> k; long long i = 0, j = 0, r = 0,q=n; long long p[20];
        for (int i = 1; i <= k-1; i++) {
            for (int j = 0; j < 20; j++) { p[j] = 0; }
            for (int j = 0; j < 20; j++) {
                if (n > 9) {
                    p[j] = n % 10;
                    n = (n - (n % 10)) / 10;
                }
                else { p[j] = n; r = j + 1; break; }
            }
            q = q + ((*min_element(p, p + r)) * (*max_element(p, p + r)));
            n = q;
        }
        cout << q << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    long long t; cin >> t;
    while (t--) {
        long long n; cin >> n; long long k; cin >> k; long long i = 0, j = 0, r = 0,q=n,yo=0; long long p[20];
        for (int i = 1; i <= k-1; i++) {
            for (int j = 0; j < 20; j++) { p[j] = 0; }
            for (int j = 0; j < 20; j++) {
                if (n > 9) {
                    p[j] = n % 10;
                    n = (n - (n % 10)) / 10;
                    if (p[j] == 0) { yo = 1; break; }
                }
                else { p[j] = n; r = j + 1; break; }
            }
            if (yo == 0) {
                q = q + ((*min_element(p, p + r)) * (*max_element(p, p + r)));
                n = q;
            }
            else {
                break;
            }
        }
        cout << q << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <new>
using namespace std;

int
main ()
{
 int t;
 cin>>t;
 while(t--){
int r = 0;

int z = 1;
    int a,n;
    cin>>a>>n;
  int k = a;

k = a;

for (int z = 1; z < n; z++)
    {

int i = 1, j = 0;

for (int i = 1; i <= 19; i++)
	{

if ((int) (k / pow (10, i)) == 0)
	    {

j = i;

break;

}

}

int *p;

p = new (nothrow) int[j];

r = k;

int q = j;

for (int q = j; q >= 1; q--)
	{

p[j - q] = (int) r / pow (10, q - 1);

r = r % (int) pow (10, q - 1);

}
k =
	k + ((*min_element (p, p + (j))) * (*max_element (p, p + (j))));

}
cout << k << endl;
}

return 0;

}


#include <iostream>
#include <cmath>
#include<algorithm>
#define ll long long
using namespace std;
void Digits(ll n , ll &largest , ll &smallest)
{
	 largest = 0;
	 smallest = 9;
	 ll r;
	while (n) {
		 r = n % 10;

		// Find the largest digit
		largest = max(r, largest);

		// Find the smallest digit
		smallest = min(r, smallest);

		n = n / 10;
	}
	//cout << largest << " " << smallest;
}
int main()
{
	int t;
	ll largest, smallest, n, k;
	cin >> t;
	while (t--)
	{
		cin >> n >> k;
		k = k - 1;
		while (k--)
		{
			Digits(n, largest, smallest);
			n = n + (largest*smallest);
			if (smallest == 0)
				break;
		}
		cout << n << endl;
	}

	return 0;
}


#include<iostream>
using namespace std;
int max(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10>p)
		p=n%10;

	}
	return p;
}
int min(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10<p)
		p=n%10;

	}
	return p;

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long a,b;
		cin>>a>>b;
		for (int i=1;i<b;i++)
		{
			a=a+min(a)*max(a);
			if(a==0)
			break;

		}
		cout<<a<<endl;

	}
}


#include<iostream>
using namespace std;
int max(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10>p)
		p=n%10;

	}
	return p;
}
int min(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10<p)
		p=n%10;

	}
	return p;

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long a,b;
		cin>>a>>b;
		for (int i=1;i<b;i++)
		{
			a=a+min(a)*max(a);

		}
		cout<<a<<endl;

	}
}


#include<iostream>
using namespace std;
int max(int n)
{
	int p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10>p)
		p=n%10;

	}
	return p;
}
int min(int n)
{
	int p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10<p)
		p=n%10;

	}
	return p;

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b;
		cin>>a>>b;
		for (int i=1;i<b;i++)
		{
			a=a+min(a)*max(a);

		}
		cout<<a<<endl;

	}
}


#include<iostream>
using namespace std;
int max(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10>p)
		p=n%10;

	}
	return p;
}
int min(long long n)
{
	long long p=n%10;
	while(n/10)
	{
		n=n/10;
		if(n%10<p)
		p=n%10;

	}
	return p;

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		long long a,b;
		cin>>a>>b;
		for (int i=1;i<b;i++)
		{
			if(min(a)==0)
			break;
			a=a+min(a)*max(a);

		}
		cout<<a<<endl;

	}
}


// Example program
#include <iostream>
#include <string>
#include <stdlib.h>     /* abs */
#include <vector>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <algorithm>
using namespace std;

typedef unsigned long long llu;
typedef long long ll;

int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}

int mindigit(llu a) {
    int min = 10;
    string s = to_string(a);
    for (char c : s) {
        int num = c - '0';
        if (num < min) {
            min = num;
        }
    }
    return min;
}

int maxdigit(llu a) {
    int max = -1;
    string s = to_string(a);
    for (char c : s) {
        int num = c - '0';
        if (num > max) {
            max = num;
        }
    }
    return max;
}

void solveA(llu a, llu k) {
    while (--k) {
        int mindig = mindigit(a);
        if (mindig == 0) {
            cout << a << endl;
            return;
        }
        a = a + mindigit(a) * maxdigit(a);
    }
    cout << a << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;

    while (t--) {
        llu a, k;
        cin >> a;
        cin >> k;

        solveA(a, k);
    }

}


// Example program
#include <iostream>
#include <string>
#include <stdlib.h>     /* abs */
#include <vector>
#include <unordered_map>
#include <limits.h>
#include <cmath>
#include <algorithm>
using namespace std;

typedef unsigned long long llu;
typedef long long ll;

int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int lcm(int a, int b)
{
    return (a * b) / gcd(a, b);
}

int mindigit(int a) {
    int min = 10;
    string s = to_string(a);
    for (char c : s) {
        int num = c - '0';
        if (num < min) {
            min = num;
        }
    }
    return min;
}

int maxdigit(int a) {
    int max = -1;
    string s = to_string(a);
    for (char c : s) {
        int num = c - '0';
        if (num > max) {
            max = num;
        }
    }
    return max;
}

void solveA(int a, int k) {
    while (--k) {
        int mindig = mindigit(a);
        if (mindig == 0) {
            cout << a << endl;
            return;
        }
        a = a + mindigit(a) * maxdigit(a);
    }
    cout << a << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;

    while (t--) {
        int a, k;
        cin >> a;
        cin >> k;

        solveA(a, k);
    }

}


#include <iostream>

int main()
{
	int t;

	std::cin >> t;

	while (t-- > 0)
	{
		long long a, k;
		std::cin >> a >> k;

		long long ak = a;
		for (long long i = 0; i < k - 1; ++i)
		{
			int min = 9, max = 0;

			while (a > 0)
			{
				int dig = a % 10;

				if (min > dig)
					min = dig;
				if (max < dig)
					max = dig;

				a /= 10;
			}

			ak += min * max;
			a = ak;

			if (min == 0)
				break;
		}

		std::cout << a << "\n";
	}
}


#include <iostream>

int main()
{
	int t;

	std::cin >> t;

	while (t-- > 0)
	{
		long long a, k;
		std::cin >> a >> k;

		long long ak = a;
		for (long long i = 0; i < k - 1; ++i)
		{
			int min = 9, max = 0;

			while (a > 0)
			{
				int dig = a % 10;

				if (min > dig)
					min = dig;
				if (max < dig)
					max = dig;

				a /= 10;
			}

			ak += min * max;
			a = ak;
		}

		std::cout << a << "\n";
	}
}


#include <iostream>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <cmath>
#include <cstring>
#include <Windows.h>
#include <sstream>
#include <typeinfo>
#include <memory>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <stdio.h>

#include <thread>
#include <chrono>
#include <algorithm>

using namespace std;

long long Max(long long n)
{
	long long max = 0;
	while (n / 10)
	{
		if (max < n % 10)
		{
			max = n % 10;
		}
		if (max == 9)
		{
			return max;
		}
		n /= 10;
	}
	if (max < n)
	{
		max = n;
	}

	return max;
}

long long Min(long long n)
{
	long long min = 9;
	while (n / 10)
	{
		if (min > n % 10)
		{
			min = n % 10;
		}
		if (min == 0)
		{
			return min;
		}
		n /= 10;
	}
	if (min > n)
	{
		min = n;
	}

	return min;
}

int main()
{

	setlocale(LC_ALL, "Rus");

	int t;
	cin >> t;
	for (int z = 0; z < t; z++)
	{
		long long n, K;
		cin >> n >> K;

		for (long long i = 1; i < K; i++)
		{
			if (Min(n) == 0 || Max(n) == 0)
			{
				cout << n << endl;
				break;
			}
			n += Max(n)*Min(n);
		}

		cout << n << endl;

		/*vector <int> a;
		for (int i = 0; i < n; i++)
		{
			int temp;
			cin >> temp;
			a.push_back(temp);
		}*/

	}

	return 0;
}


#include <iostream>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <cmath>
#include <cstring>
#include <Windows.h>
#include <sstream>
#include <typeinfo>
#include <memory>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <stdio.h>

#include <thread>
#include <chrono>
#include <algorithm>

using namespace std;

long long Max(long long n)
{
	long long max = 0;
	while (n / 10)
	{
		if (max < n % 10)
		{
			max = n % 10;
		}
		if (max == 9)
		{
			return max;
		}
		n /= 10;
	}
	if (max < n)
	{
		max = n;
	}

	return max;
}

long long Min(long long n)
{
	long long min = 9;
	while (n / 10)
	{
		if (min > n % 10)
		{
			min = n % 10;
		}
		if (min == 0)
		{
			return min;
		}
		n /= 10;
	}
	if (min > n)
	{
		min = n;
	}

	return min;
}

int main()
{

	setlocale(LC_ALL, "Rus");

	int t;
	cin >> t;
	for (int z = 0; z < t; z++)
	{
		long long n, K;
		cin >> n >> K;

		for (int i = 1; i < K; i++)
		{
			if (Min(n) == 0 || Max(n) == 0)
			{
				cout << n << endl;
				break;
			}
			n += Max(n)*Min(n);
		}

		cout << n << endl;

		/*vector <int> a;
		for (int i = 0; i < n; i++)
		{
			int temp;
			cin >> temp;
			a.push_back(temp);
		}*/

	}

	return 0;
}


#include <iostream>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <cmath>
#include <cstring>
#include <Windows.h>
#include <sstream>
#include <typeinfo>
#include <memory>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <stdio.h>

#include <thread>
#include <chrono>
#include <algorithm>

using namespace std;

long long Max(long long n)
{
	long long max = 0;
	while (n / 10)
	{
		if (max < n % 10)
		{
			max = n % 10;
		}
		if (max == 9)
		{
			return max;
		}
		n /= 10;
	}
	if (max < n)
	{
		max = n;
	}

	return max;
}

long long Min(long long n)
{
	long long min = 9;
	while (n / 10)
	{
		if (min > n % 10)
		{
			min = n % 10;
		}
		if (min == 0)
		{
			return min;
		}
		n /= 10;
	}
	if (min > n)
	{
		min = n;
	}

	return min;
}

int main()
{

	setlocale(LC_ALL, "Rus");

	int t;
	cin >> t;
	for (int z = 0; z < t; z++)
	{
		long long n, K;
		cin >> n >> K;

		for (long long i = 1; i < K; i++)
		{
			if (Min(n) == 0 || Max(n) == 0)
			{
				break;
			}
			n += Max(n)*Min(n);
		}

		cout << n << endl;

		/*vector <int> a;
		for (int i = 0; i < n; i++)
		{
			int temp;
			cin >> temp;
			a.push_back(temp);
		}*/

	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma warning (disable :4996)

long long int K = 0, ans = 0, min = 1000, max = 0, k = 1, sum = 0;
long long int a(long long int n);

int main() {

	int cases = 0;
	scanf("%d", &cases);
	for (int c = 0; c < cases; c++) {
		min = 1000;
		max = 0;
		k = 1;
		scanf("%lld %lld", &ans, &K);

		printf("%lld\n", a(ans));
	}

//	system("pause");
	return 0;
}

long long int a(long long int n) {

	if (k >= K) return ans;
	bool zero = false;
	sum = n;
	min = 100;
	max = 0;
	for (int i = 0; sum > 0; i++) {
		if (sum % 10 > max) max = sum % 10;
		if (sum % 10 < min) min = sum % 10;
		if (sum % 10 == 0) {
			zero = true;
			break;
		}
		sum = sum / 10;
	}
	ans =  n + min*max;
	k++;
	if (zero == true) return ans;
	return a(ans);

}


#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void Digits(int n,int & largest,int & smallest)
{
	largest = 0;
	smallest = 9;

	while (n) {
		int r = n % 10;

		// Find the largest digit
		largest = max(r, largest);

		// Find the smallest digit
		smallest = min(r, smallest);

		n = n / 10;
	}

}
int main()
{

	int n;
	int a, k;
	int result = 0;
	int s = 0, l = 0;
	cin >> n;
	while (n > 0)
	{
		cin >> a >> k;
		result = a;
		for (int i = 0;i < k-1;i++)
		{
			Digits(result,l,s);
			result = result + s * l;
		}
		cout << result << endl;
		n--;
	}

	return 0;
}


#include<bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long INT;

#define NN 300010

int a[NN], b[NN];
multiset<int> st;

int solve(int n) {
	st.clear();
	for(int i=1; i<=n; i++) {
		if(a[i] == b[i]) {
			continue;
		}
		st.insert(b[i]);
		int pos = i;
		i++;
		for(; i<=n; i++) {
			if(b[i] < b[i-1]) return 0;
			st.insert(b[i]);
			while(st.size() and st.find(a[pos]) != st.end()) {
				st.erase(st.find(a[pos++]));
			}
			if(pos == i + 1) break;
		}
	}
	if(st.size()) return 0;
	return 1;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	int T;
	cin >> T;
	while(T--) {
		int n;
		cin >> n;
		for(int i=1; i<=n; i++) cin >> a[i];
		for(int i=1; i<=n; i++) cin >> b[i];
		int flag = 1;
		if(!solve(n)) puts("NO");
		else puts("YES");
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FASTIO
// #define endl "\n"  // Since endl forces a buffer flush which lows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (ll i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*prllf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (ll i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (ll i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

// What follows is a magical ordered_set data structure.
// Supports the following functions:
// find_by_order(ll k) - returns k'th smallest element (0-indexed)
// order_of_key(ll k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update>

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 polls by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> prll;
typedef vector<ll> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 998244353;
const long double eps = 1e-7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// long long true_rand(long long n)
// {
// 	// Returns a random number between 0 and n - 1 inclusive using mt19937.
//     uniform_ll_distribution<long long> uid(0, n - 1);
//     return uid(rng);
// }

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}
ll count_inv(ll l, ll r, ll * a)
{
	ll count=0;
	if(l==r)
		return 0;
	ll mid = (l+r)/2;
	count+= count_inv(l,mid,a)+count_inv(mid+1,r,a);
	vector <ll> b,c,d;
	for(ll i=l ; i<=mid ; i++)
		b.pb(a[i]);
	for(ll i=mid+1 ; i<=r ; i++)
		c.pb(a[i]);
	while(!(b.empty()&& c.empty()))
	{
		if(b.empty())
		{
			d.pb(c.back());
			c.pop_back();
		}
		else if(c.empty())
		{
			d.pb(b.back());
			b.pop_back();
		}
		else
		{
			if(b.back()>c.back())
			{
				d.pb(b.back());
				b.pop_back();
				count+=c.size();
			}
			else
			{
				d.pb(c.back());
				c.pop_back();
				//count+=b.size();

			}
		}
	}
	reverse(d.begin(),d.end());
	for(ll i=l ; i<=r ; i++)
	{
		a[i]=d[i-l];
	}
	return count;

}

const ll N = 2e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	// TRY BINARY SEARCH. Always at least once.

	ll t;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		ll a[n + 5] = {}, b[n + 5] = {};
		vi pos[n + 5] = {};
		ll gt[n + 5] = {};
		forl(i, 0, n)
		{
			cin >> a[i];
			pos[a[i]].pb(i);
		}
		ordered_set st2;
		for (ll i = n - 1; i >= 0; --i)
		{
			gt[i] = st2.order_of_key(a[i]);
			gt[i] = (ll)st2.size() - gt[i];
			st2.insert(a[i]);
		}

		forl(i, 0, n)
		{
			cin >> b[i];
		}
		ordered_set st;
		ll fail = 0;
		for (ll i = n - 1; i >= 0; --i)
		{
			ll x = b[i];
			ll len = (ll)pos[x].size();
			// Only swapping plix.
			if (len <= 0)
			{
				fail = 1;
				break;
			}

			ll idx = pos[x][len - 1];

			ll lesser = st.order_of_key(x);
			ll greater = (ll)st.size() - lesser;
			if (gt[idx] > greater)
			{
				fail = 1;
				// dugbe(i);
				break;
			}

			pos[x].pop_back();
			st.insert(b[i]);
		}
		if(count_inv(0,n-1,a)<count_inv(0,n-1,b))
			fail=1;
		if (fail)
			cout << "NO\n";
		else
			cout << "YES\n";
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FASTIO
// #define endl "\n"  // Since endl forces a buffer flush which lows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (ll i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*prllf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (ll i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (ll i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

// What follows is a magical ordered_set data structure.
// Supports the following functions:
// find_by_order(ll k) - returns k'th smallest element (0-indexed)
// order_of_key(ll k) - returns number of elements strictly smaller than k.
using namespace __gnu_pbds;
#define ordered_set tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update>

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 polls by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pr;
typedef pair<ll, ll> prll;
typedef vector<ll> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 998244353;
const long double eps = 1e-7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long true_rand(long long n)
{
	// Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_ll_distribution<long long> uid(0, n - 1);
    return uid(rng);
}

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}
ll count_inv(ll l, ll r, ll * a)
{
	ll count=0;
	if(l==r)
		return 0;
	ll mid = (l+r)/2;
	count+= count_inv(l,mid,a)+count_inv(mid+1,r,a);
	vector <ll> b,c,d;
	for(ll i=l ; i<=mid ; i++)
		b.pb(a[i]);
	for(ll i=mid+1 ; i<=r ; i++)
		c.pb(a[i]);
	while(!(b.empty()&& c.empty()))
	{
		if(b.empty())
		{
			d.pb(c.back());
			c.pop_back();
		}
		else if(c.empty())
		{
			d.pb(b.back());
			b.pop_back();
		}
		else
		{
			if(b.back()>c.back())
			{
				d.pb(b.back());
				b.pop_back();
				count+=c.size();
			}
			else
			{
				d.pb(c.back());
				c.pop_back();
				//count+=b.size();

			}
		}
	}
	reverse(d.begin(),d.end());
	for(ll i=l ; i<=r ; i++)
	{
		a[i]=d[i-l];
	}
	return count;

}

const ll N = 2e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	// TRY BINARY SEARCH. Always at least once.

	ll t;
	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		ll a[n + 5] = {}, b[n + 5] = {};
		vi pos[n + 5] = {};
		ll gt[n + 5] = {};
		forl(i, 0, n)
		{
			cin >> a[i];
			pos[a[i]].pb(i);
		}
		ordered_set st2;
		for (ll i = n - 1; i >= 0; --i)
		{
			gt[i] = st2.order_of_key(a[i]);
			gt[i] = (ll)st2.size() - gt[i];
			st2.insert(a[i]);
		}

		forl(i, 0, n)
		{
			cin >> b[i];
		}
		ordered_set st;
		ll fail = 0;
		for (ll i = n - 1; i >= 0; --i)
		{
			ll x = b[i];
			ll len = (ll)pos[x].size();
			// Only swapping plix.
			if (len <= 0)
			{
				fail = 1;
				break;
			}

			ll idx = pos[x][len - 1];

			ll lesser = st.order_of_key(x);
			ll greater = (ll)st.size() - lesser;
			if (gt[idx] > greater)
			{
				fail = 1;
				// dugbe(i);
				break;
			}

			pos[x].pop_back();
			st.insert(b[i]);
		}
		if(count_inv(0,n-1,a)<count_inv(0,n-1,b))
			fail=1;
		if (fail)
			cout << "NO\n";
		else
			cout << "YES\n";
	}

	return 0;
}