#include <bits/stdc++.h>
#define ll long long
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define mmst(i,a) memset(i,a,sizeof(i))
#define all(i) i.begin(),i.end()
#define allr(i) i.rbegin(),i.rend()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define SS " "
#define ddd cout<<"D"<<endl;
#define dd(i) cout<<i<<endl;
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
const char nl = '\n';
using namespace std;

const ll mod = 1e9 + 7;
const ll sz = 9e8;
const ll inf = 1e18;
ll ocr, incr;

void solve()
{
    ll s,k;cin>>s>>k;
    ll ans = s * k;
    auto getNd = [&](ll op) -> ll{
        ll nw = s;
        if(nw % 10 == 5)nw += 5;
        if(nw % 10 == 0)return nw;
        while(nw % 10 != 2){
            // ddd
            nw += (nw % 10);
            op--;
            if(op == 0)break;
        }
        ll dv = op / ocr;
        op = op % 4;
        nw += dv * incr;
        // cout<<op<<nl;
        while(op > 0){
            nw += (nw % 10);
            op--;
        }
        return nw;
    };
    /*
        #include <bits/stdc++.h>
        #define ll long long
        #define fr(i, a, b) for (ll i = a; i < b; i++)
        #define mmst(i,a) memset(i,a,sizeof(i))
        #define all(i) i.begin(),i.end()
        #define allr(i) i.rbegin(),i.rend()
        #define fast                          \
            ios_base::sync_with_stdio(false); \
            cin.tie(NULL);                    \
            cout.tie(NULL);
        #define SS " "
        #define ddd cout<<"D"<<endl;
        #define dd(i) cout<<i<<endl;
        #define yes cout << "Yes" << endl
        #define no cout << "No" << endl
        const char nl = '\n';
        using namespace std;

        const ll mod = 1e9 + 7;
        const ll sz = 9e8;
        const ll inf = 1e18;
        ll ocr, incr;

        void solve()
        {
            ll s,k;cin>>s>>k;
            ll ans;
            auto getNd = [&](ll op) -> ll{
                ll nw = s;
                ll dv = op / 4;
                op = op % 4;
                nw = nw + dv * 20;
                // cout<<op<<nl;
                // while(op > 0){
                //     nw += (nw % 10);
                //     op--;
                // }
                return nw;
            };
            ll op1 = 355748884, op2 = 355753907,op3 = 355758828;
            // cout<<op1<<nl;
            cout<<op2<<nl;
            // cout<<op3<<nl;
            // cout<<getNd(op1) * (k - op1)<<nl;
            cout<<getNd(op2) * (k - op2 + (op2 % 4))<<nl;
            // cout<<getNd(op3) * (k - op3)<<nl;
            ll m1 = 355753904 / 4;
            ll a1 = s + 20 * m1;
            ll z1 = (k - m1 * 4) * a1;
            cout<<z1<<nl;
            while(op2 > 0){
                s += (s % 10);
                op2--;
                k--;
            }
            ans = s * k;
            cout<<ans<<nl;
        }

        int main()
        {
            fast ll T = 1;
            // cin >> T;
            ocr = 4, incr = 20;
            for (int tc = 1; tc <= T; tc++)
            {
                // cout<<"Case "<<tc<<": ";
                solve();
            }
            return 0;
        }
    */
    // cout<<sz<<nl;
    for (int i = 0; i < 4; ++i) {
        ll lo = 1, hi = k, mid1, mid2;
        if (k > 0) {
            while((hi - lo) >= 400){
                mid1 = (hi - lo) / 3 + lo;
                mid2 = hi - (hi - lo) / 3;
                ll asbe1 = getNd(mid1) * (k - mid1);
                ll asbe2 = getNd(mid2) * (k - mid2);
                if(asbe1 >= asbe2){
                    ans = max(ans, asbe1);
                    hi = mid2 - 1;
                }
                else{
                    ans = max(ans, asbe2);
                    lo = mid1 + 1;
                }
            }
            for(ll j = lo; j <= hi; j++){
                ans = max(ans, getNd(i) * (k - i));
            }
            k--;
            s = s + s % 10;
            ans = max(ans, k * s);
        }
    }
    // while(lo <= hi){
    //     mid1 = (hi - lo) / 3 + lo;
    //     mid2 = hi - (hi - lo) / 3;
    //     ll asbe1 = getNd(mid1) * (k - mid1);
    //     ll asbe2 = getNd(mid2) * (k - mid2);
    //     if(asbe1 >= asbe2){
    //         ans = max(ans, asbe1);
    //         hi = mid2 - 1;
    //     }
    //     else{
    //         ans = max(ans, asbe2);
    //         lo = mid1 + 1;
    //     }
    //     if(hi == 355753906)cout<<mid1<<SS<<asbe1<<SS<<mid2<<SS<<asbe2<<nl;
    //     // cout<<lo<<SS<<hi<<nl;
    // }
    cout<<ans<<nl;
}

int main()
{
    fast ll T = 1;
    cin >> T;
    ocr = 4, incr = 20;
    for (int tc = 1; tc <= T; tc++)
    {
        // cout<<"Case "<<tc<<": ";
        solve();
    }
    return 0;
}