#include <bits/stdc++.h>
using namespace std;
const long long inf = 1ll << 62;
long long read() {
  long long s = 0ll;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10ll + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(long long x) {
  if (x < 0ll) {
    putchar('-');
    x = -x;
  }
  if (x < 10ll)
    putchar(x + '0');
  else {
    write(x / 10ll);
    putchar(x % 10ll + '0');
  }
}
void print(long long x, char c = '\n') {
  write(x);
  putchar(c);
}
long long sum[10ll];
long long num[20ll];
int main() {
  long long T = read();
  while (T--) {
    long long ans = inf;
    long long m = read(), n = read();
    for (long long i = 0ll; i <= 9ll; i++) sum[i] = 0ll;
    for (long long i = 0ll; i <= 9ll; i++)
      for (long long j = i; j <= i + n; j++) sum[i] += j % 10ll;
    for (long long i = 0ll; i <= 9ll; i++)
      if (i + n > 9ll) {
        for (long long j = 0ll; j <= 17ll; j++)
          if ((m - 9ll * j * (10ll - i) - (i + n - 9ll) - sum[i]) % (n + 1ll) ==
                  0ll &&
              m - 9ll * j * (10ll - i) - (i + n - 9ll) - sum[i] >= 0ll) {
            long long now =
                (m - 9ll * j * (10ll - i) - (i + n - 9ll) - sum[i]) / (n + 1ll);
            long long cnt = 0ll, tmp = 0ll;
            num[++cnt] = i;
            for (long long k = 1ll; k <= j; k++) num[++cnt] = 9ll;
            num[++cnt] = min(now, 8ll);
            now -= min(now, 8ll);
            while (now) {
              num[++cnt] = min(now, 9ll);
              now -= min(now, 9ll);
            }
            for (long long i = cnt; i >= 1ll; i--) tmp = tmp * 10ll + num[i];
            ans = min(ans, tmp);
          }
      } else if ((m - sum[i]) % (n + 1ll) == 0ll && m - sum[i] >= 0ll) {
        long long cnt = 0ll, now = (m - sum[i]) / (n + 1ll), tmp = 0ll;
        num[++cnt] = i;
        while (now) {
          num[++cnt] = min(now, 9ll);
          now -= min(now, 9ll);
        }
        for (long long i = cnt; i >= 1; i--) tmp = tmp * 10ll + num[i];
        ans = min(ans, tmp);
      }
    if (ans == inf)
      puts("-1");
    else
      print(ans);
  }
  return 0;
}
