#include <bits/stdc++.h>
using namespace std;
long long T, n, k, ans;
inline void solve() {
  ans = 1e18;
  for (register long long now = 0; now <= 9; ++now) {
    if (now + k <= 9) {
      long long last = n - (now * (k + 1) + (1 + k) * k / 2);
      if (last < 0 || last % (k + 1) != 0) continue;
      last /= (k + 1);
      long long num = now, bin = 1;
      while (last) {
        bin *= 10;
        if (last >= 9)
          last -= 9, num = bin * 9 + num;
        else
          num = bin * last + num, last = 0;
      }
      ans = min(ans, num);
    } else {
      long long l = now;
      long long len1 = 9 - l + 1;
      long long r = (k + 1) - len1 - 1;
      long long len2 = r - 0 + 1;
      long long last = n - (now * len1 + (0 + len1 - 1) * len1 / 2);
      if (last < 0) continue;
      last = last - (0 + r) * (r + 1) / 2;
      if (last < 0) continue;
      for (register long long i = 0; i <= 17; ++i) {
        long long lastt = last + len2 * 9 * i - len2;
        if (lastt % (len1 + len2) != 0) continue;
        lastt /= (len1 + len2);
        if (lastt < 9 * i) continue;
        long long num = now, bin = 1;
        for (register long long j = 1; j <= i; ++j) {
          bin *= 10;
          lastt -= 9;
          num = bin * 9 + num;
        }
        if (lastt >= 8) {
          bin *= 10;
          lastt -= 8;
          num = bin * 8 + num;
          while (lastt) {
            bin *= 10;
            if (lastt >= 9)
              lastt -= 9, num = bin * 9 + num;
            else
              num = bin * lastt + num, lastt = 0;
          }
        } else {
          bin *= 10;
          num = bin * lastt + num, lastt = 0;
        }
        ans = min(ans, num);
      }
    }
  }
  if (ans == 1e18)
    puts("-1");
  else
    printf("%lld\n", ans);
}
signed main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &n, &k);
    solve();
  }
  return 0;
}
