#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){
/*
    for(ll i = 9989ll; i <= 1000000000ll; i+=1000ll){
        if((sum(i) + sum(i+1)) %2 == 0){
            cout << i << ' ' << sum(i) + sum(i+1) << endl;
        }
    }
    100000
     99989
    cout << endl;
    return;*/

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 80){
                    for(int i = 0; i <= 100000; i++){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 99989ll; i <= 1000000000ll; i += 100000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        int ceiling;
        if(k==2 && n%3){
            cout << -1 << endl;
            return;
        }else{
            ceiling = 699997;
        }
        if(k>=3){
            ceiling = 79989;
        }
        for(int i = 0; i <= ceiling; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    //cout << 150 << endl;
    //for(int i = 1; i<=150; i++)
    //    cout << i << " 3" << endl;
    //return 0;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i <= 699997; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        int ceiling;
        if(k==2 && n%3){
            cout << -1 << endl;
            return;
        }else{
            ceiling = 699997;
        }
        if(k>=3){
            ceiling = 79989;
        }
        if(k>=5){
            ceiling = 3000;
        }
        for(int i = 0; i <= ceiling; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    //cout << 150 << endl;
    //for(int i = 1; i<=150; i++)
    //    cout << i << " 5" << endl;
    //return 0;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){

    /*for(int i = 89; i <= 100000; i+=100){
        if((sum(i) + sum(i+1)) %2 == 0){
            cout << i << ' ' << sum(i) + sum(i+1) << endl;
        }
    }
    cout << endl;
    return;
*/
    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 80){
                    for(int i = 0; i <= 10000; i++){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 99989ll; i <= 1000000000ll; i += 10000ll){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define st first
#define nd second
#define pb push_back
#define popb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x));
#define deb(x) cout << #x << " = " << x << endl
#define debv(x) cout << #x << ": "; for (int i = 0; i < (x).size(); i++) cout << (x)[i] << ' '; cout << endl
#define PI 3.1415926535897932384626
#define fastio ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); srand(time(NULL)); cout << fixed << setprecision(1)
typedef pair< int ,int >                pii;
typedef pair< long long, long long >    pll;
typedef vector< pii >                   vii;
typedef vector< pll >                   vll;
typedef long long                       ll;
typedef map< int, int >                 mii;
typedef set< pii >                      sii;
typedef set< int >                      si;
typedef vector< int >                   vi;
typedef vector< ll >                    vl;
typedef long double                     ld;
typedef pair< ld, ld >                  pld;
typedef vector< pld >                   vpld;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//ordered_set t;
//t.insert(val);
//t.find_by_order(i) - returns iterator to the i-th element in set
//t.order_of_key(i) - index of value i

const ll mod = 1e9 + 7;                 /// 1 000 000 007
const ll mod2 = 119 << 23 | 1;          /// 998244353
const ll mod3 = 467'093'870'598'391;    /// big prime
int inf = 1e9 + 7;
ll INF = 1e14 + 9;

///tagliatelle here
///

ll power (ll x, ll y);
ll inv (ll x);
bool isPrime (ll x);
ll gcd (ll x, ll y);

//================================================================================

const int nax = 2e5 + 13;

void prep(){

}

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

void solve(){

    int n, k;
    cin >> n >> k;
    if(k > 1){
        for(int i = 0; i < 1000000; i++){
            int ans = 0;
            for(int j = 0; j <= k; j++)
                ans += sum(i + j);
            if(ans == n){
                cout << i << '\n';
                return;
            }
        }
        cout << -1 << '\n';
    }else{
        if(k == 0){
            string res;
            while(n >= 9){
                res.pb('9');
                n -= 9;
            }
            if(n > 0){
                res.pb('0' + n);
            }
            reverse(all(res));
            cout << res << '\n';
        }else{
            string res;
            if(n % 2){
                //normal
                n++;
                while(n > 18){
                    res.pb('9');
                    n -= 18;
                }
                if(n > 1)
                    res.pb('0' + (n / 2));
                res[0]--;
                reverse(all(res));
                cout << res << '\n';
            }else{
                //fucked up
                if(n < 10){
                    cout << -1 << '\n';
                    return;
                }else if(n <= 98){
                    for(int i = 9; i <= 1000000; i+=10){
                        if(sum(i) + sum(i+1) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }else{
                    for(ll i = 999989ll; i <= 100000000000ll; i += 1000000ll){
                        if(sum(i) + sum(i+1ll) == n){
                            cout << i << '\n';
                            return;
                        }
                    }
                }
            }
        }
    }

}

int main(){            ///use cin and printf if you wanna see some REAL SPEED
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    fastio;
    int T = 1;
    prep();
    cin >> T;
    for(int i = 1; i <= T; i++){
        //cout << "test case " << i << endl;
        solve();
    }
    return 0;
}

ll power (ll x, ll y) {
    ll res = 1ll;
    x %= mod;
    if (x == 0)
        return 0;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1ll;
        x = (x * x) % mod;
    }
    return res;
}

ll inv (ll x) {
    ll r = 1ll, t = x, k = mod - 2ll;
    while (k) {
        if (k & 1ll) r = r * t % mod;
        t = (long long) t * t % mod;
        k >>= 1;
    }
    return r;
}

bool isPrime (ll x) {
    if (x == 1)
        return false;
    for (ll i = 2ll; i * i <= x; i++) {
        if (x % i == 0)
            return false;
    }
    return true;
}

ll gcd (ll x, ll y) {
    if (!y)
        return x;
    return gcd (y, x % y);
}

/*
    __builtin_popcount
    __builtin_ctz
    __builtin_clz
*/


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        lint ret = inf;
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = s;
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != inf) {
            cout << ret << "\n";
            continue;
        }
        if (n < maxi) {
            cout << -1 << "\n";
            continue;
        }
        for (auto &p : sums) {
            for (int z = 0; z < 20; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    vector<lint> res;
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res.push_back(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res.push_back(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    lint temp = p[2];
                    lint tens = 10;
                    for (auto &r : res) {
                        temp += r * tens;
                        tens *= 10;
                    }
                    ret = min(ret, temp);
                }
            }
        }
        if (ret != inf) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        auto minis = [](string l, string r) {
            if (l.size() == r.size())
                return min(l, r);
            else if (l.size() < r.size())
                return l;
            else
                return r;
        };
        string ret = to_string(inf);
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = to_string(s);
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
            continue;
        }
        if (n < maxi) {
            cout << -1 << "\n";
            continue;
        }
        for (auto &p : sums) {
            for (int z = 0; z < 20; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (((n - p[0] + 8) / 9 + k) / (k + 1) < z)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    string res = string(1, '0' + p[2]);
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res += to_string(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res += to_string(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    reverse(res.begin(), res.end());
                    ret = minis(ret, res);
                }
            }
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        lint ret = inf;
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = s;
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != inf) {
            cout << ret << "\n";
            continue;
        }
        if (n < maxi) {
            cout << -1 << "\n";
            continue;
        }
        for (auto &p : sums) {
            for (int z = 0; z < 3; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (((n - p[0] + 8) / 9 + k) / (k + 1) < z)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    vector<lint> res;
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res.push_back(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res.push_back(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    lint temp = p[2];
                    lint tens = 10;
                    for (auto &r : res) {
                        temp += r * tens;
                        tens *= 10;
                    }
                    ret = min(ret, temp);
                }
            }
        }
        if (ret != inf) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        lint ret = inf;
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = s;
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != inf) {
            cout << ret << "\n";
            continue;
        }
        if (n < maxi) {
            cout << -1 << "\n";
            continue;
        }
        for (auto &p : sums) {
            for (int z = 0; z < 20; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (((n - p[0] + 8) / 9 + k) / (k + 1) < z)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    vector<lint> res;
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res.push_back(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res.push_back(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    lint temp = p[2];
                    lint tens = 10;
                    for (auto &r : res) {
                        temp += r * tens;
                        tens *= 10;
                    }
                    ret = min(ret, temp);
                }
            }
        }
        if (ret != inf) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        auto minis = [](string l, string r) {
            if (l.size() == r.size())
                return min(l, r);
            else if (l.size() < r.size())
                return l;
            else
                return r;
        };
        string ret = to_string(inf);
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = to_string(s);
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
            continue;
        }
        // if (n < maxi) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        for (auto &p : sums) {
            for (int z = 0; z < 20; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (((n - p[0] + 8) / 9) / (k + 1) < z)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    string res = string(1, '0' + p[2]);
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res += to_string(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res += to_string(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    reverse(res.begin(), res.end());
                    ret = minis(ret, res);
                }
            }
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        auto minis = [](string l, string r) {
            if (l.size() == r.size())
                return min(l, r);
            else if (l.size() < r.size())
                return l;
            else
                return r;
        };
        string ret = to_string(inf);
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = to_string(s);
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
            continue;
        }
        // if (n < maxi) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        for (auto &p : sums) {
            for (int z = 0; z < 20; ++z) {
                lint digi = n - p[0] + 9 * z * p[1];
                if (p[1] == 0 && z == 1)
                    break;
                if (digi < 0)
                    continue;
                if (((n - p[0] + 8) / 9 + k) / (k + 1) < z)
                    continue;
                if (digi % (k + 1) == 0) {
                    digi /= (k + 1);
                    string res = string(1, '0' + p[2]);
                    for (int i = 0; i < 1000; ++i) {
                        if (i == z && p[1] != 0) {
                            lint add = min(8ll, digi);
                            digi -= add;
                            res += to_string(add);
                        } else {
                            lint add = min(9ll, digi);
                            digi -= add;
                            res += to_string(add);
                        }
                        if (digi == 0)
                            break;
                    }
                    reverse(res.begin(), res.end());
                    ret = minis(ret, res);
                }
            }
        }
        if (ret != to_string(inf)) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

lint digit(lint n) {
    lint ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        lint n, k;
        cin >> n >> k;
        // lint mini = (0 + k) * (k + 1) / 2;
        // if (n < mini) {
        //     cout << -1 << "\n";
        //     continue;
        // }
        lint ret = inf;
        vector<array<lint, 3>> sums;
        lint maxi = 0;
        for (int s = 0; s <= 9; ++s) {
            lint d   = 0;
            lint ten = 0;
            for (int t = s; t <= s + k; ++t) {
                d += digit(t);
                if (t >= 10)
                    ten++;
            }
            if (d == n) {
                ret = s;
                break;
            }
            maxi = max(maxi, d);
            sums.push_back({d, ten, s});
        }
        if (ret != inf) {
            cout << ret << "\n";
            continue;
        }
        if (n < maxi) {
            cout << -1 << "\n";
            continue;
        }
        for (auto &p : sums) {
            lint digi = n - p[0];
            if (digi % (k + 1) == 0) {
                digi /= (k + 1);
                vector<lint> res;
                for (int i = 0; i < 1000; ++i) {
                    if (i == 0 && p[1] != 0) {
                        lint add = min(8ll, digi);
                        digi -= add;
                        res.push_back(add);
                    } else {
                        lint add = min(9ll, digi);
                        digi -= add;
                        res.push_back(add);
                    }
                    if (digi == 0)
                        break;
                }
                lint temp = p[2];
                lint tens = 10;
                for (auto &r : res) {
                    temp += r * tens;
                    tens *= 10;
                }
                ret = min(ret, temp);
            }
        }
        if (ret != inf) {
            cout << ret << "\n";
        } else {
            cout << -1 << "\n";
        }
    }
    return 0;
}


// 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 = 1'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 - 1;
            if (sm >= 116)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999989;
    GET1[120] = 29999989;
    GET1[122] = 39999989;
    GET1[124] = 49999989;
    GET1[126] = 59999989;
    GET1[128] = 69999989;
    GET1[130] = 79999989;
    GET1[132] = 89999989;
    GET1[134] = 99999989;
    GET1[136] = 199999989;
    GET1[138] = 299999989;
    GET1[140] = 399999989;
    GET1[142] = 499999989;
    GET1[144] = 599999989;
    GET1[146] = 699999989;
    GET1[148] = 799999989;
    GET1[150] = 899999989;
}

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]);
        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()
{

    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 MAXD = 6'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 - 1;
            if (sm >= 116)
            {
                break;
            }
        }
        i += 10;
    }
    GET1[118] = 19999989;
    GET1[120] = 29999989;
    GET1[122] = 39999989;
    GET1[124] = 49999989;
    GET1[126] = 59999989;
    GET1[128] = 69999989;
    GET1[130] = 79999989;
    GET1[132] = 89999989;
    GET1[134] = 99999989;
    GET1[136] = 199999989;
    GET1[138] = 299999989;
    GET1[140] = 399999989;
    GET1[142] = 499999989;
    GET1[144] = 599999989;
    GET1[146] = 699999989;
    GET1[148] = 799999989;
    GET1[150] = 899999989;
}

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]);
        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 = 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]);
    }
}

void k2p()
{
    FOR0(i, MAXN)
    {
        fill_n(K2P[i], 10, -1);
    }
    FOR0(i, MAXD)
    {
        ll t = i;
        while (t)
        {
            SD[i] += t % 10;
            t /= 10;
        }
    }
    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 MAXD = 6'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 - 20)
    {
        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 = 4'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 MAXD = 3'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 (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 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 >= 134)
            {
                break;
            }
        }
        i += 10;
    }
    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, 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();
    }
}


// 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 = 7'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 MAXD = 4'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 (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 MAXD = 3'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 MAXD = 2'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 (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 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 >= 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, 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();
    }
}


// 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 (j < 2)
            {
                continue;
            }
            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();
    }
}