#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const int inf = 1000000007;   const int MOD = 1000000007;   int f(int x) {     int res = 0;     while (x > 0) {       res += x % 10;       x /= 10;     }     return res;   }   bool calc(int n, int k) {     int sm = 0;     for (int i = 0; i < k; ++i) {       sm += f(i);     }     for (int i = k; i <= 100000; ++i) {       sm += f(i);       if (sm == n) {         cout << i - k <<   n ;         return true;       }       sm -= f(i - k);     }     if (n <= 45) {       cout << -1 <<   n ;       return true;     }     return false;   }   void solve() {     int n, k;     cin >> n >> k;     if (calc(n, k)) return;     n -= k * (k + 1) / 2;     if (n < 0) {       cout << -1 <<   n ;       return;     }     int top = 0;     string mid;     int last = 0;     int cnt = 0;     while (n % (k + 1) != 0) {       n += 9;       cnt++;       if (cnt > 9) {         cout << -1 <<   n ;         return;       }     }     if (n - cnt * 9 < (k - cnt) * 9) {       cout << -1 <<   n ;       return;     }     last = 9 - (k - cnt);     n /= (k + 1);     n -= last;     while (n > 9) {       n -= 9;       mid +=  9 ;     }     top = n;     if (cnt > 0) {       int l = mid.length();       if (l != 0) {         mid[l - 1] =  8 ;         top++;       }     }     string hoge;     while (top > 9) {       top -= 9;       hoge +=  9 ;     }     if (top > 0) cout << top;     cout << hoge << mid << last <<   n ;   }   signed main() {     int t;     cin >> t;     for (int i = 0; i < t; ++i) solve();     return 0;   }   