#include <bits/stdc++.h>
using namespace std;
long long cal(long long key) {
  if (key <= 8) return key;
  key -= 8;
  long long prefix = key % 9;
  key -= prefix;
  while (key) {
    prefix *= 10;
    prefix += min(key, (long long)9);
    key -= min(key, (long long)9);
  }
  prefix = prefix * 10 + 8;
  return prefix;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test, n, k, i, d, p, count9, num, ans, t;
  cin >> test;
  while (test--) {
    cin >> n >> k;
    ans = 1e18;
    p = 1;
    for (count9 = 0; count9 < 17; count9++) {
      p *= 10;
      for (d = 0; d < 10; d++) {
        t = min(10 - d, k + 1);
        num = n - count9 * t * 9 - (k + 1 - t);
        for (i = 0; i <= k; i++) num -= (d + i) % 10;
        if (num >= 0 && num % (k + 1) == 0) {
          num /= (k + 1);
          ans = min(ans, cal(num) * p + p - 10 + d);
        }
      }
    }
    if (ans == 1e18)
      cout << "-1\n";
    else
      cout << ans << "\n";
  }
  return 0;
}
