#include <bits/stdc++.h>
using namespace std;
long long f(long long x) {
  long long r = 0;
  while (x > 0) {
    r += x % 10;
    x /= 10;
  }
  return r;
}
long long __pow(long long x, long long e) {
  if (e == 0) {
    return 1;
  }
  long long r = __pow(x, e / 2);
  r = r * r;
  if (e % 2 == 1) {
    r = r * x;
  }
  return r;
}
long long concat(long long a, long long b) {
  long long r = 0, i = 0;
  for (; b > 0; i++) {
    r = (b % 10) * __pow(10, i) + r;
    b /= 10;
  }
  i = max(i, 1ll);
  for (; a > 0; i++) {
    r = (a % 10) * __pow(10, i) + r;
    a /= 10;
  }
  return r;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long ans = LLONG_MAX;
    long long n, k;
    cin >> n >> k;
    for (long long r = 0; r <= 9; r++) {
      for (long long y = 0;; y = 10 * y + 9) {
        long long s = 0;
        for (long long x = 10 * y + r; x <= 10 * y + r + k; x++) {
          s += f(x);
        }
        if (s > n) {
          break;
        }
        if ((n - s) % (k + 1) == 0) {
          long long m = (n - s) / (k + 1);
          long long z = min(m, 8ll);
          m -= min(m, 8ll);
          for (long long i = 1; m > 0; i++) {
            z = min(m, 9ll) * __pow(10, i) + z;
            m -= min(m, 9ll);
          }
          ans = min(ans, concat(z, 10 * y + r));
        }
      }
    }
    cout << (ans == LLONG_MAX ? -1 : ans) << endl;
  }
}
