#include <bits/stdc++.h>
using namespace std;
int calc(long long x) {
  int res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, k;
    scanf("%d%d", &n, &k);
    long long ans = 1e18;
    for (int x = 0; x <= 9; x++) {
      for (int y = 0; y * 9 + x <= n; y++) {
        int num = n;
        long long t = 0;
        for (int i = 1; i <= y; i++) t = t * 10 + 9;
        t = t * 10 + x;
        for (int i = 0; i <= k; i++) num -= calc(t + i);
        if (num >= 0 && num % (k + 1) == 0) {
          int tmp = num / (k + 1);
          long long p = 10;
          for (int i = 1; i <= y; i++) p *= 10;
          for (int i = 1;; i++) {
            int up = 9;
            if (i == 1) up = 8;
            if (tmp <= up) {
              t += p * tmp;
              break;
            }
            t += up * p;
            p *= 10;
            tmp -= up;
          }
          ans = min(ans, t);
        }
      }
    }
    if (ans == 1e18) ans = -1;
    printf("%lld\n", ans);
  }
  return 0;
}
