#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long pwr(long long x, long long y) {
  long long ret = 1;
  for (long long i = 1; i <= y; i++) ret *= x;
  return ret;
}
int main() {
  long long T, n, k, ans;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    ans = INF;
    for (long long sg, tmp, val, dt, i = 0; i <= 9; i++) {
      sg = 0;
      for (long long j = i; j <= i + k; j++) sg += j % 10;
      if (i + k >= 10) continue;
      tmp = n - sg;
      if (tmp < 0 || tmp % (k + 1)) continue;
      tmp = tmp / (k + 1);
      val = i;
      dt = 10;
      while (tmp) {
        if (tmp >= 9) {
          val += dt * 9;
          tmp -= 9;
        } else {
          val += dt * tmp;
          tmp = 0;
        }
        dt *= 10;
      }
      ans = min(ans, val);
    }
    for (long long d = 0; d <= 16; d++) {
      for (long long sg, x, tmp, val, dt, i = 0; i <= 9; i++) {
        sg = 0;
        for (long long j = i; j <= i + k; j++) sg += j % 10;
        if (i + k < 10) continue;
        x = 10 - i;
        tmp = n - (9 * x * d + sg + (k + 1 - x));
        if (tmp < 0 || tmp % (k + 1)) continue;
        tmp = tmp / (k + 1);
        val = pwr(10, d + 1) - 10 + i;
        dt = pwr(10, d + 2);
        if (tmp <= 8)
          val += pwr(10, d + 1) * tmp;
        else {
          val += pwr(10, d + 1) * 8;
          tmp -= 8;
          while (tmp) {
            if (tmp >= 9) {
              val += dt * 9;
              tmp -= 9;
            } else {
              val += dt * tmp;
              tmp = 0;
            }
            dt *= 10;
          }
        }
        ans = min(ans, val);
      }
    }
    if (ans == INF) ans = -1;
    cout << ans << '\n';
  }
  return 0;
}
