#include <bits/stdc++.h>   using namespace std;   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (long long i = 0; i < static_cast<long long>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <class A, class B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <class A, class B, class C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <class A, class B, class C, class D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   template <class A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <class Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << to_string(arg1) <<   n ;   }   template <class Arg1, class... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << to_string(arg1) <<   |  ;     __f(comma + 1, args...);   }   const long long inf = (long long)4e18;   long long sum(long long x) {     long long s = 0;     for (; x; x /= 10) {       s += (x % 10);     }     return s;   }   long long to_int(string s) {     long long res = 0;     for (long long i = 0; i < (long long)s.size(); i++) {       res *= 10;       res += s[i] -  0 ;     }     return res;   }   void solve() {     long long n, k;     cin >> n >> k;     long long ans = inf;     for (long long d = 0; d < 10; d++) {       for (long long cnt = 0; cnt < 18; cnt++) {         long long cur = cnt * 9 + d;         if (cur > n) break;         long long x = 0;         for (long long i = 0; i < cnt; i++) {           x += 9;           x *= 10;         }         x += d;         long long su = 0;         for (long long i = 0; i <= k; i++) {           su += sum(x + i);         }         69;         su -= max(0LL, k + 1 - (10 - d));         if (su > n) continue;         for (long long d1 = 0; d1 < 9; d1++) {           long long p = min(k + 1, 10 - d);           long long new_su = su + d1 * p + (d1 + 1) * (k + 1 - p);           if (new_su > n) continue;           if (new_su == n) {             if (d1 > 0) {               string tmp = to_string(d1) + to_string(x);               ans = min(ans, to_int(tmp));             } else {               ans = min(ans, x);             }             continue;           }           long long rem = n - new_su;           if (rem % (k + 1) != 0) continue;           rem /= (k + 1);           long long f = rem % 9;           rem -= f;           for (long long it = 0; it < rem / 9; it++) {             f *= 10;             f += 9;           }           if (f > 0) {             f *= 10;             f += d1;           }           69;           if (f == 0) {             ans = min(ans, x);           } else {             string q = to_string(f) + to_string(x);             ans = min(ans, to_int(q));           }         }       }     }     if (ans == inf) {       cout <<  -1 n ;     } else {       cout << ans <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }   