#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second < b.second : a.first < b.first;
}
long long int modInverse(long long int a) {
  long long int m = 998244353;
  long long int y = 0, x = 1;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += 998244353;
  return x;
}
long long int binpow(long long int a, long long int p) {
  if (p == 0) return 1;
  long long int ret = binpow(a, p / 2);
  ret *= ret;
  ret %= 998244353;
  if (p % 2) {
    ret *= a;
    ret %= 998244353;
  }
  return ret;
}
string makeans(int mx, int need, int k) {
  string ans;
  if (!need) {
    if (mx < 10) {
      ans += '0' + mx;
    } else {
      ans += '0' + mx / 10;
      ans += '0' + mx % 10;
    }
  } else {
    ans += '0' + mx % 10;
    ans += '0' + mx / 10;
    if (mx + k > 99) {
      if (need >= 9) {
        ans += '8';
        need -= 8;
      } else {
        ans += '0' + need;
        need = 0;
      }
    }
    while (need) {
      if (need > 9) {
        ans += '9';
        need -= 9;
      } else {
        ans += '0' + need;
        need = 0;
      }
    }
    reverse(ans.begin(), ans.end());
  }
  return ans;
}
bool isansbig(string &a, string &b) {
  for (int i = 0; i < a.size(); i++) {
    if (a[i] > b[i])
      return 1;
    else if (b[i] > a[i])
      return 0;
  }
  return 0;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int mx = -1, need;
  string ans;
  for (int i = 0; i < 100; i++) {
    int cnt = 0;
    for (int j = 0; j < k + 1; j++) {
      int nw = i + j;
      while (nw) {
        cnt += nw % 10;
        nw /= 10;
      }
    }
    if (n >= cnt && (n - cnt) % (k + 1) == 0) {
      string chck = makeans(i, (n - cnt) / (k + 1), k);
      if (ans.empty() || (ans.size() > chck.size()) ||
          (ans.size() == chck.size() && isansbig(ans, chck)))
        ans = chck;
    }
  }
  if (ans.size() == 0)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1, nw = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
