#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18 + 5;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, k;
    scanf("%d %d", &n, &k);
    long long ans = inf;
    for (int bit = 0; bit < 10; bit++) {
      int bitsum = (bit + bit + k) * (k + 1) / 2;
      if (bit + k < 10) {
        if (n < bitsum) continue;
        if ((n - bitsum) % (k + 1)) continue;
        int pre = (n - bitsum) / (k + 1);
        long long ret = bit;
        for (long long base = 10; pre; base *= 10) {
          int d = min(pre, 9);
          pre -= d;
          ret += d * base;
        }
        ans = min(ans, ret);
      } else {
        int bitsum = 0;
        for (int i = 0; i <= k; i++) bitsum += (bit + i) % 10;
        for (int i = 0; i < 17; i++) {
          int sum = bitsum;
          sum += (10 - bit) * 9 * i;
          sum += (bit + k) % 10 + 1;
          if (n < sum) continue;
          if ((n - sum) % (k + 1)) continue;
          long long ret = bit, base = 10;
          for (int j = 1; j <= i; j++) {
            ret += 9 * base;
            base *= 10;
          }
          int pre = (n - sum) / (k + 1);
          int d = min(pre, 8);
          ret += d * base;
          pre -= d;
          base *= 10;
          long long lim = 1e18;
          for (; pre; base *= 10) {
            if (base == lim) break;
            int d = min(pre, 9);
            ret += d * base;
            pre -= d;
          }
          if (pre) continue;
          ans = min(ans, ret);
        }
      }
    }
    printf("%lld\n", ans == inf ? -1 : ans);
  }
  return 0;
}
