#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
ll modlaber(ll a, ll m = 1000000007) { return ((a + m) % m + m) % m; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  auto checkit = [&](string a, string b) {
    if (a.length() != b.length())
      return a.length() < b.length();
    else
      return a < b;
  };
  int __;
  cin >> __;
  while (__--) {
    ll n, k;
    cin >> n >> k;
    string ans(20, '9');
    if (!k) {
      if (n % 9 != 0) cout << char('0' + n % 9);
      cout << string(n / 9, '9') << "\n";
      continue;
    }
    for (ll nines = (0); nines < (16); nines++) {
      for (ll last = (0); last < (10); last++) {
        ll now = 0;
        for (ll i = (last); i < (last + k + 1); i++)
          if (i <= 9)
            now += nines * 9 + i;
          else
            now += i - 10 + 1;
        ll m = (n - now) / (k + 1);
        if (n - now >= 0 && (n - now) % (k + 1) == 0) {
          string temp;
          if (m) temp += char('0' + min(m, 8ll)), m -= min(m, 8ll);
          while (m) temp = char('0' + min(m, 9ll)) + temp, m -= min(m, 9ll);
          for (ll j = (0); j < (nines); j++) temp += '9';
          temp += '0' + last;
          if (checkit(temp, ans)) ans = temp;
        }
      }
    }
    cout << (ans.length() < 20 ? ans : "-1") << "\n";
  }
  return 0;
}
