// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

const int MAXN = 155;
const int MAXD = 700'700;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

ll K1[MAXN];
ll K2P[MAXN][20];
ll SD[MAXD];

ll k0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void k1()
{
    string TMP[MAXN];
    for (ll i = 10; i <= 26; i += 2)
    {
        TMP[i] = to_string((i / 2 - 4) * 10);
    }
    for (ll i = 28; i <= 150; i += 2)
    {
        TMP[i] = TMP[i - 18];
        TMP[i].pop_back();
        TMP[i] += "90";
    }
    fill_n(K1, MAXN, -1);
    for (ll i = 10; i <= 150; i += 2)
    {
        K1[i] = stoi(TMP[i]) - 1;
    }
}

void k2p()
{
    FOR0(i, MAXD)
    {
        ll t = i;
        while (t)
        {
            SD[i] += t % 10;
            t /= 10;
        }
    }
    FOR0(i, MAXN)
    {
        fill_n(K2P[i], 10, -1);
    }
    FOR0(i, MAXD - 20)
    {
        ll s = 0;
        FOR0(j, 10)
        {
            s += SD[i + j];
            if (s > 150)
            {
                break;
            }
            if (K2P[s][j] == -1)
            {
                K2P[s][j] = i;
            }
        }
    }
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", k0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", k0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", K1[n]);
        return;
    }
    printf("%lld\n", K2P[n][k]);
}

int main()
{
    k1();
    k2p();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//const int MAXN = -1;
const int MAXD = 1'000'000;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

map<ll, ll> GET1;
ll DIGSUM[MAXD];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{
    FOR0(i, 151)
    {
        GET1[i] = -1;
    }
    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (!GET1[sm])
        {
            GET1[sm] = i;
            if (sm >= 118)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999990;
    GET1[120] = 29999990;
    GET1[122] = 39999990;
    GET1[124] = 49999990;
    GET1[126] = 59999990;
    GET1[128] = 69999990;
    GET1[130] = 79999990;
    GET1[132] = 89999990;
    GET1[134] = 99999990;
    GET1[136] = 199999990;
    GET1[138] = 299999990;
    GET1[140] = 399999990;
    GET1[142] = 499999990;
    GET1[144] = 599999990;
    GET1[146] = 699999990;
    GET1[148] = 799999990;
    GET1[150] = 899999990;
}

void get2plus()
{
    FOR0(i, MAXD)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    vector<ll> cnt(10, 0);
    FOR0(i, MAXD)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
                ++cnt[j];
                /*if (j == 2)
                {
                    error(j, cursum, i);
                }*/
            }
        }
    }
    /*FOR0(i, 10)
    {
        error(cnt[i]);
    }*/
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n]);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//const int MAXN = -1;
const int MAXD = 1'000'000;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

map<ll, ll> GET1;
ll DIGSUM[MAXD];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{
    FOR0(i, 151)
    {
        GET1[i] = -1;
    }
    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (GET1[sm] == -1)
        {
            GET1[sm] = i;
            if (sm >= 118)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999990;
    GET1[120] = 29999990;
    GET1[122] = 39999990;
    GET1[124] = 49999990;
    GET1[126] = 59999990;
    GET1[128] = 69999990;
    GET1[130] = 79999990;
    GET1[132] = 89999990;
    GET1[134] = 99999990;
    GET1[136] = 199999990;
    GET1[138] = 299999990;
    GET1[140] = 399999990;
    GET1[142] = 499999990;
    GET1[144] = 599999990;
    GET1[146] = 699999990;
    GET1[148] = 799999990;
    GET1[150] = 899999990;
}

void get2plus()
{
    FOR0(i, MAXD)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    vector<ll> cnt(10, 0);
    FOR0(i, MAXD)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
                ++cnt[j];
                /*if (j == 2)
                {
                    error(j, cursum, i);
                }*/
            }
        }
    }
    /*FOR0(i, 10)
    {
        error(cnt[i]);
    }*/
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n] - 1);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//const int MAXN = -1;
const int MAXD = 1'000'000;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

map<ll, ll> GET1;
ll DIGSUM[MAXD];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{
    FOR0(i, 151)
    {
        GET1[i] = -1;
    }
    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (GET1[sm] == -1)
        {
            GET1[sm] = i;
            if (sm >= 118)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999990;
    GET1[120] = 29999990;
    GET1[122] = 39999990;
    GET1[124] = 49999990;
    GET1[126] = 59999990;
    GET1[128] = 69999990;
    GET1[130] = 79999990;
    GET1[132] = 89999990;
    GET1[134] = 99999990;
    GET1[136] = 199999990;
    GET1[138] = 299999990;
    GET1[140] = 399999990;
    GET1[142] = 499999990;
    GET1[144] = 599999990;
    GET1[146] = 699999990;
    GET1[148] = 799999990;
    GET1[150] = 899999990;
}

void get2plus()
{
    FOR0(i, MAXD + 100)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    vector<ll> cnt(10, 0);
    FOR0(i, MAXD)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
                ++cnt[j];
            }
        }
    }
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n] - 1);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

const int MAXD = 5'000'000;

map<ll, ll> GET1;
ll DIGSUM[MAXD];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{
    FOR0(i, 151)
    {
        GET1[i] = -1;
    }
    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (GET1[sm] == -1)
        {
            GET1[sm] = i;
            if (sm >= 116)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999990;
    GET1[120] = 29999990;
    GET1[122] = 39999990;
    GET1[124] = 49999990;
    GET1[126] = 59999990;
    GET1[128] = 69999990;
    GET1[130] = 79999990;
    GET1[132] = 89999990;
    GET1[134] = 99999990;
    GET1[136] = 199999990;
    GET1[138] = 299999990;
    GET1[140] = 399999990;
    GET1[142] = 499999990;
    GET1[144] = 599999990;
    GET1[146] = 699999990;
    GET1[148] = 799999990;
    GET1[150] = 899999990;
}

void get2plus()
{
    FOR0(i, MAXD)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    FOR0(i, MAXD - 20)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (cursum > 150)
            {
                break;
            }
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
            }
        }
    }
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n] - 1);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//const int MAXN = -1;
const int MAXD = 1'000'000;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

map<ll, ll> GET1;
ll DIGSUM[MAXD];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{
    FOR0(i, 151)
    {
        GET1[i] = -1;
    }
    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (GET1[sm] == -1)
        {
            GET1[sm] = i;
            if (sm >= 118)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999990;
    GET1[120] = 29999990;
    GET1[122] = 39999990;
    GET1[124] = 49999990;
    GET1[126] = 59999990;
    GET1[128] = 69999990;
    GET1[130] = 79999990;
    GET1[132] = 89999990;
    GET1[134] = 99999990;
    GET1[136] = 199999990;
    GET1[138] = 299999990;
    GET1[140] = 399999990;
    GET1[142] = 499999990;
    GET1[144] = 599999990;
    GET1[146] = 699999990;
    GET1[148] = 799999990;
    GET1[150] = 899999990;
}

void get2plus()
{
    FOR0(i, MAXD)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    vector<ll> cnt(10, 0);
    FOR0(i, MAXD)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
                ++cnt[j];
                /*if (j == 2)
                {
                    error(j, cursum, i);
                }*/
            }
        }
    }
    /*FOR0(i, 10)
    {
        error(cnt[i]);
    }*/
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n]);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


// g++ -std=c++17 -Wall -O2 a.cpp
// GET RID OF WARNINGS
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FOR0(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define scf(a) scanf("%lld", &a)
using namespace std;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
#define error(args...)                           \
    {                                            \
        string _s = #args;                       \
        replace(_s.begin(), _s.end(), ',', ' '); \
        stringstream _ss(_s);                    \
        istream_iterator<string> _it(_ss);       \
        err(_it, args);                          \
    }
void err(istream_iterator<string> it)
{
}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

//const int MAXN = -1;
//const int MAXM = -1;
//const ll MINLL = -9'223'372'036'854'775'807;
//const ll MAXLL = 9'223'372'036'854'775'807;
//const int MOD = 1'000'000'007;
//const ll INF = -1;
//const double PI = 3.14159265358979323846;
//const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

map<ll, ll> GET1;
ll DIGSUM[1'001'000];
map<ll, map<ll, ll>> ANS;

ll sumdigits(ll x)
{
    ll ans = 0;
    while (x)
    {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

ll get0(ll n)
{
    ll ans = 0, mult = 1;
    while (n)
    {
        ans += min(9LL, n) * mult;
        n -= min(9LL, n);
        mult *= 10;
    }
    return ans;
}

void get1()
{

    ll i = 10;
    while (true)
    {
        ll sm = sumdigits(i) + sumdigits(i - 1);
        if (sm % 2)
        {
            i += 10;
            continue;
        }
        if (!GET1[sm])
        {
            GET1[sm] = i;
            if (sm > 150)
            {
                break;
            }
        }
        i += 10;
    }
}

void get2plus()
{
    FOR0(i, 1'000'100)
    {
        DIGSUM[i] = sumdigits(i);
    }
    FOR0(i, 151)
    {
        FOR0(j, 10)
        {
            ANS[i][j] = -1;
        }
    }
    FOR0(i, 1'000'000)
    {
        ll cursum = 0;
        FOR0(j, 10)
        {
            cursum += DIGSUM[i + j];
            if (ANS[cursum][j] == -1)
            {
                ANS[cursum][j] = i;
            }
        }
    }
}

void solve()
{
    ll n, k;
    scf(n);
    scf(k);
    if (k == 0)
    {
        printf("%lld\n", get0(n));
        return;
    }
    if (k == 1)
    {
        if (n % 2)
        {
            printf("%lld\n", get0((n + 1) / 2) - 1);
            return;
        }
        printf("%lld\n", GET1[n]);
        return;
    }
    printf("%lld\n", ANS[n][k]);
}

int main()
{
    get1();
    get2plus();
    ll t;
    scf(t);
    FOR0(_, t)
    {
        solve();
    }
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 23; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {
                    if (go % 9) {
                        if (go < 9) {
                            s += ('0' + go);
                        }

                        else {
                            int was = go % 9;
                            s += '8';
                            go -= 8;
                            while (go >= 9) {
                                s += '9';
                                go -= 9;
                            }

                            s += ('9' - (8 - was));
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                while (t.size() > 1 && t.back() == '0') t.pop_back();

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 309; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {

                    if (go % 9) {
                        s += (go % 9 + '0');
                        go -= go % 9;

                        while (go) {
                            s += '9';
                            go -= 9;
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                while (t.size() > 1 && t.back() == '0') t.pop_back();

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 150; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {

                    if (go % 9) {
                        s += (go % 9 + '0');
                        go -= go % 9;

                        while (go) {
                            s += '9';
                            go -= 9;
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                reverse(s.begin(), s.end());
                if (answ[0] == '-' || s.size() < answ.size() || (s.size() == answ.size() && s < answ)) {
                    answ = s;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 23; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {
                    if (go % 9) {
                        s += (go % 9 + '0');
                        go -= go % 9;

                        while (go) {
                            s += '9';
                            go -= 9;
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                while (t.size() > 1 && t.back() == '0') t.pop_back();

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 159; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {

                    if (go % 9) {
                        s += (go % 9 + '0');
                        go -= go % 9;

                        while (go) {
                            s += '9';
                            go -= 9;
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                reverse(s.begin(), s.end());
                if (answ[0] == '-' || s.size() < answ.size() || (s.size() == answ.size() && s < answ)) {
                    answ = s;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 23; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {
                    if (go % 9) {
                        if (go < 9) {
                            s += ('0' + go);
                        }

                        else {
                            int was = go % 9;
                            s += '8';
                            go -= 8;
                            while (go >= 9) {
                                go -= 9;
                            }

                            s += ('9' - (8 - was));
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                while (t.size() > 1 && t.back() == '0') t.pop_back();

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 309; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {

                    if (go % 9) {
                        s += (go % 9 + '0');
                        go -= go % 9;

                        while (go) {
                            s += '9';
                            go -= 9;
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define x first
#define y second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(chrono::high_resolution_clock::now().time_since_epoch().count());
int randlr(int l, int r) {
    return rand1() % (r - l + 1);
}

signed main() {
    ios :: sync_with_stdio(0);
    cin.tie(0);

    int ttt;
    cin >> ttt;

    while (ttt--) {
        int n, k;
        cin >> n >> k;

        string answ = "-1";
        for (int m = 0; m <= 23; m++) {
            for (int st = 9; st > -1; st--) {
                int curr = 0, last = st, ch = 0;
                for (int i = 0; i <= k; i++) {
                    if (last == 10) {
                        ch = 1;
                        last = 0;
                    }

                    if (ch) {
                        curr += last + 1;
                    }

                    else {
                        curr += 9 * m + last;
                    }

                    last++;
                }

                if (curr > n || (n - curr) % (k + 1)) continue;
                string s = "";
                s += (st + '0');
                int go = (n - curr) / (k + 1);
                for (int i = 0; i < m; i ++) s += '9';

                if (ch) {
                    if (go % 9) {
                        if (go < 9) {
                            s += ('0' + go);
                        }

                        else {
                            int was = go % 9;
                            s += '8';
                            go -= 8;
                            while (go > 9) {
                                s += '9';
                                go -= 9;
                            }

                            s += ('9' - (8 - was));
                        }
                    }

                    else if (go != 0) {
                        s += '8';
                        go -= 8;
                        while (go > 9) {
                            s += '9';
                            go -= 9;
                        }

                        s += '1';
                    }
                }

                else {
                    while (go > 9) {
                        s += '9';
                        go -= 9;
                    }

                    if (go != 0)
                        s += (go + '0');
                }

                int sum = 0;
                string t = s;

                for (int it = 0; it <= k; it++) {
                    for (auto u : s) sum += (u - '0');
                    int i = 0;
                    while (i < s.size() && s[i] == '9') {
                        s[i] = '0';
                        i++;
                    }

                    if (i == s.size()) s += '1';
                    else s[i]++;
                }

                if (sum != n) continue;

                while (t.size() > 1 && t.back() == '0') t.pop_back();

                reverse(t.begin(), t.end());

                if (answ[0] == '-' || t.size() < answ.size() || (t.size() == answ.size() && t < answ)) {
                    answ = t;
                    //cout << answ << ' ' << curr << ' ' << st << ' ' << m << endl;
                }
            }
        }

        cout << answ << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
int _, n, k;
long long ans = 2e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=2e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				long long cur=0, e=(n-s)/(k+1);
				for(long long i=1; e>0; e-=i==1?8:9, i*=10)
					cur += std::min(i==1?8:9ll, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				ans = std::min(ans, cur*10+d);
			}
		}
		printf("%lld\n", ans>1e18?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 2e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=2e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=i==1?8:9, i*=10)
					cur += min(i==1?8:9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				ans = min(ans, cur*10+d);
			}
		}
		printf("%lld\n", ans>1e18?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 1e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=1e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=9, i*=10)
					cur += min(9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				if (d==0) cur*=10;
				for(int i=d; i; i/=10) cur*=10;
				ans = min(ans, cur+d);
			}
		}
		printf("%lld\n", ans>1e17?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 1e18;
long long sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=1e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			long long s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=9, i*=10)
					cur += min(9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				if (d==0) cur*=10;
				for(int i=d; i; i/=10) cur*=10;
				ans = min(ans, cur+d);
			}
		}
		printf("%lld\n", ans>1e17?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 2e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=2e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=9, i*=10)
					cur += min(9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				if (d==0) cur*=10;
				for(int i=d; i; i/=10) cur*=10;
				ans = min(ans, cur+d);
			}
		}
		printf("%lld\n", ans>1e18?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 2e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=2e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=18; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=9, i*=10)
					cur += min(9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				ans = min(ans, cur*10+d);
			}
		}
		printf("%lld\n", ans>1e18?-1:ans);
	}
}


#include <bits/stdc++.h>
using namespace std;
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
int _, n, k;
long long ans = 2e18;
int sum(int d, int x) {
	int res=0;
	for(int i=0; i<=k; i++) {
		for(int y=d+i; y; y/=10)
			res += y%10;
		if (d+i<10) res += x*9;
	}
	return res;
}
int main() {
	for(scanf("%d", &_); _--; ans=1e18) {
		scanf("%d%d", &n, &k);
		for(int d=0; d<=9; d++) for(int x=0; x<=17; x++) {
			int s = sum(d, x);
			if (n>=s && (n-s)%(k+1) == 0) {
				int e = (n-s)/(k+1);
				long long cur=0;
				for(long long i=1; e>0; e-=9, i*=10)
					cur += min(9, e)*i;
				for(int i=0; i<x; i++)
					if(cur==0) cur=9;
					else cur*=10, cur+=9;
				if (d==0) cur*=10;
				for(int i=d; i; i/=10) cur*=10;
				ans = min(ans, cur+d);
			}
		}
		printf("%lld\n", ans>1e18?-1:ans);
	}
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=50;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        if((d%(len-x-2))>0) continue;
                        d/=(len-x-2);
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=100;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        if((d%(len-x-2))>0) continue;
                        d/=(len-x-2);
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=30;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if((d%(k+1))>0) continue;
                        d/=(k+1);
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=40;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        if((d%(len-x-2))>0) continue;
                        d/=(len-x-2);
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=30;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        if((d%(len-x-2))>0) continue;
                        d/=(len-x-2);
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int digits(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=(x%10);
        x/=10;
    }
    return sum;
}

string solve(ll x,int n,int k)
{
    int sum=0;
    for(ll a=x;a<=x+k;a++) sum+=digits(a);
    if(sum==n) return to_string(x);
    else return "";
}

string mn(string a,string b)
{
    if(a.empty()) return b;
    if(a.size()<b.size()||(a.size()==b.size()&&a<b)) return a;
    else return b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--)
    {
        int n,k;
        cin >> n >> k;
        string res;
        for(int len=1;len<=17;len++)
        {
            ll x=stoll(string(len,'9'));
            for(int i=0;i<=9;i++)
            {
                string temp=solve(10*x+i,n,k);
                if(!temp.empty()) res=mn(res,temp);
            }
        }
        for(int i=0;i<=9;i++)
        {
            string temp=solve(i,n,k);
            if(!temp.empty()) res=mn(res,temp);
        }
        for(int len=2;len<=40;len++)
        {
            for(int a=0;a<=9;a++)
            {
                for(int x=0;x<=len-2;x++)
                {
                    for(int b=1;b<=8;b++)
                    {
                        int cnt=10-a;
                        int now=0;
                        for(int j=0;j<=k;j++) now+=((a+j)%10);
                        now+=min(cnt,k+1)*9*x;
                        now+=min(cnt,k+1)*b+max(0,k+1-cnt)*(b+1);
                        int d=n-now;
                        string two=to_string(b)+string(x,'9')+to_string(a);
                        if(x==len-2)
                        {
                            if(d==0) res=mn(res,two);
                            continue;
                        }
                        if(d<(len-x-2)*1) continue;
                        if(d>(len-x-2)*9) continue;
                        if((d%(len-x-2))>0) continue;
                        d/=(len-x-2);
                        string one;
                        int low=1;
                        for(int i=1;i<=len-x-2;i++)
                        {
                            for(int j=low;j<=9;j++)
                            {
                                if(d-j<=(len-x-2-i)*9)
                                {
                                    one+=('0'+j);
                                    d-=j;
                                    low=j;
                                    break;
                                }
                            }
                        }
                        res=mn(res,one+two);
                    }
                }
            }
        }
        if(!res.empty()) cout << res << "\n";
        else cout << "-1\n";
    }
    return 0;
}


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n, bool x = 0)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		while(c--)
			a.push_back(i);
		n %= i;
	}
	sort(all(a));
	if (x)
	{
		if (!a.empty() && a[0] == 9)
		{
			a.push_back(0);
			sort(all(a));
		}
		reverse(all(a));
		for (int i = 0; i < a.size(); i++)
			if (a[i] != 9)
			{
				swap(a[0], a[i]);
				break;
			}
		reverse(all(a));
		if (a.size() > 1)
			for (int i = 0; i < a.size()-1; i++)
				while (a[i] > 1 && a.back() < 8)
				{
					a[i]--;
					a.back()++;
				}
	}
	for (int i = 0; i < a.size(); i++)
		res = res * 10 + a[i];
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15 && n > 0; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2,1);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
					//cout << "!!!!" << answ << endl;
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		cout << answ << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	/*for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}*/

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i];
		for (int j = 1; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n, bool x = 0)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		while(c--)
			a.push_back(i);
		n %= i;
	}
	sort(all(a));
	if (x)
	{
		reverse(all(a));
		for (int i = 0; i < a.size(); i++)
			if (a[i] != 9)
			{
				swap(a[0], a[i]);
				break;
			}
		reverse(all(a));
		if (a.size() > 1)
			for (int i = 0; i < a.size()-1; i++)
				while (a[i] > 1 && a.back() < 8)
				{
					a[i]--;
					a.back()++;
				}
	}
	for (int i = 0; i < a.size(); i++)
		res = res * 10 + a[i];
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15 && n > 0; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
					//cout << "!!!!" << answ << endl;
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		cout << answ << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	/*for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}*/

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i];
		for (int j = 1; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		ans[n][k] = answ;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}
LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += cnt(x + i);
	return res;
}

int fastCnt(int x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL l = fnd(n / 2 + n % 2);
		LL r = l + 10000;
		l = max(0ll, l - 10000);
		for(int i=l;i<=r;i++)
			if (get(i) == n)
			{
				cout << i << endl;
				break;
			}
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		while(c--)
			a.push_back(i);
		n %= i;
	}
	sort(all(a));
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		if (a[i] != 9)
		{
			swap(a[0], a[i]);
			break;
		}
	reverse(all(a));
	if (a.size() > 1)
		while (a[0] > 1 && a.back() < 8)
		{
			a[0]--;
			a.back()++;
		}
	for (int i = 0; i < a.size(); i++)
		res = res * 10 + a[i];
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15 && n > 0; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
					//cout << "!!!!" << answ << endl;
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		cout << answ << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	/*for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}*/

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i];
		for (int j = 1; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		while(c--)
			a.push_back(i);
		n %= i;
	}
	sort(all(a));
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		if (a[i] != 9)
		{
			swap(a[0], a[i]);
			break;
		}
	reverse(all(a));
	if (a.size() > 1)
		while (a[0] > 1 && a.back() < 8)
		{
			a[0]--;
			a.back()++;
		}
	for (int i = 0; i < a.size(); i++)
		res = res * 10 + a[i];
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15 && n > 0; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
					//cout << "!!!!" << answ << endl;
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		else
			used[n][k] = 1;
		ans[n][k] = answ;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	/*for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}*/

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i];
		for (int j = 1; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(LL x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	cout << x << " : " << res << endl;
	return res;
}

LL fnd(int n, bool x = 0)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		while(c--)
			a.push_back(i);
		n %= i;
	}
	sort(all(a));
	if (x)
	{
		reverse(all(a));
		for (int i = 0; i < a.size(); i++)
			if (a[i] != 9)
			{
				swap(a[0], a[i]);
				break;
			}
		reverse(all(a));
		if (a.size() > 1)
			for (int i = 0; i < a.size()-1; i++)
				while (a[i] > 1 && a.back() < 8)
				{
					a[i]--;
					a.back()++;
				}
	}
	for (int i = 0; i < a.size(); i++)
		res = res * 10 + a[i];
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL answ = mod * mod;
		for (int i = 0; i <= 15 && n > 0; i++)
		{
			if ((n-1) % 2 == 0)
			{
				LL res = fnd((n - 1) / 2,1);
				if (res % 10 != 9)
				{
					for (int j = 0; j < i; j++)
						res = res * 10 + 9;
					answ = min(answ, res);
					//cout << "!!!!" << answ << endl;
				}
			}
			n -= 9;
		}
		if (answ == mod * mod)
			answ = -1;
		cout << answ << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	/*for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}*/

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i];
		for (int j = 1; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}
LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += cnt(x + i);
	return res;
}

int fastCnt(int x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}
LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += cnt(x + i);
	return res;
}

int fastCnt(int x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}
LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += cnt(x + i);
	return res;
}

int fastCnt(int x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL l = fnd(n / 2 + n % 2);
		LL r = l + 10000;
		l = max(0ll, l - 10000);
		for(int i=l;i<=r;i++)
			if (get(i) == n)
			{
				cout << i << endl;
				return;
			}
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}

int fastCnt(LL x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL l = fnd(n / 2 + n % 2);
		LL r = l + 10000;
		l = max(0ll, l - 10000);
		for(int i=l;i<=r;i++)
			if (get(i) == n)
			{
				cout << i << endl;
				return;
			}
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/


/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0)
using namespace std;

const int N = 10000007;

int n,k;
int sum[N], ans[100005][15],used[100005][15];

LL cnt(LL x)
{
	LL res = 0;
	while (x)
	{
		res += x % 10;
		x /= 10;
	}
	return res;
}
LL get(int x)
{
	LL res = 0;
	for (LL i = 0; i <= k; i++)
		res += fastCnt(x + i);
	return res;
}

int fastCnt(int x)
{
	int res = 0;
	res += x % 10;
	x /= 10;
	res += x % 10;
	x /= 10;
	res += sum[x];
	return res;
}

LL fnd(int n)
{
	LL res = 0;
	vector<int> a;
	for (int i = 9; i >= 1; i--)
	{
		int c = n / i;
		a.push_back(c);
		n %= i;
	}
	reverse(all(a));
	for (int i = 0; i < a.size(); i++)
		while (a[i]--)
			res = res * 10 + i + 1;
	return res;
}

void solve()
{
	cin >> n >> k;
	if (k == 0)
	{
		cout << fnd(n) << endl;
		return;
	}
	if (k == 1)
	{
		LL l = fnd(n / 2 + n % 2);
		LL r = l + 10000;
		l = max(0ll, l - 10000);
		for(int i=l;i<=r;i++)
			if (get(i) == n)
			{
				cout << i << endl;
				return;
			}
	}
	if (used[n][k] == 0)
		ans[n][k] = -1;
	cout << ans[n][k] << endl;
}

int main()
{
	fastIO;

	for (int i = 1; i <= 10000000; i++)
	{
		sum[i] = sum[i / 10] + i % 10;
	}

	for (int i = 0; i < 100000000; i++)
	{
		int val = fastCnt(i) + fastCnt(i + 1);
		if (!used[val][1])
		{
			ans[val][1] = i;
			used[val][1] = 1;
		}
	}

	for (int i = 0; i <= 10000000; i++)
	{
		int val = sum[i] + sum[i + 1];
		for (int j = 2; j <= 9 && i + j <= 10000000; j++)
		{
			val += sum[i + j];
			if (!used[val][j])
			{
				ans[val][j] = i;
				used[val][j] = 1;
			}
		}
	}

	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}

/*

*/