#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 998244353LL;
const int maxn = 2e5 + 5;
struct Answer {
  int a[205], len;
  bool operator<(const Answer &rhs) const {
    if (len != rhs.len) return len < rhs.len;
    for (int i = 0; i < len; ++i) {
      if (a[i] != rhs.a[i]) return a[i] < rhs.a[i];
    }
    return false;
  }
};
int n, k;
void make1(Answer &x) {
  int val = n - k * (k + 1) / 2;
  if (val < 0 || val % (k + 1) != 0) {
    x.len = inf;
    return;
  }
  int sum = val / (k + 1);
  stack<int> s;
  int dig = min(sum, 9 - k);
  s.push(dig);
  sum -= dig;
  while (sum > 0) {
    if (sum >= 9) {
      s.push(9);
      sum -= 9;
    } else {
      s.push(sum);
      sum = 0;
    }
  }
  x.len = 0;
  while (!s.empty()) {
    x.a[x.len++] = s.top();
    s.pop();
  }
}
void make2(Answer &x, int y, int z, int sum) {
  stack<int> s;
  s.push(y);
  for (int i = 0; i < z; ++i) {
    s.push(9);
  }
  int dig = min(sum, 8);
  if (dig > 0) {
    s.push(dig);
    sum -= dig;
  }
  while (sum > 0) {
    if (sum >= 9) {
      s.push(9);
      sum -= 9;
    } else {
      s.push(sum);
      sum = 0;
    }
  }
  x.len = 0;
  while (!s.empty()) {
    x.a[x.len++] = s.top();
    s.pop();
  }
}
int ds[105];
void output(Answer &ans) {
  if (ans.len == inf) {
    puts("-1");
  } else {
    for (int i = 0; i < ans.len; ++i) {
      printf("%d", ans.a[i]);
    }
    puts("");
  }
}
void solve() {
  scanf("%d%d", &n, &k);
  for (int y = 10 - k; y < 10; ++y) {
    ds[y] = 0;
    for (int i = 0; i <= k; ++i) {
      ds[y] += (y + i) % 10;
      ds[y] += (y + i) / 10;
    }
  }
  Answer ans;
  make1(ans);
  for (int z = 0; z < 50; ++z) {
    for (int y = 10 - k; y < 10; ++y) {
      int val = (10 - y) * z * 9 + ds[y];
      val = n - val;
      if (val < 0 || val % (k + 1) != 0) continue;
      val /= (k + 1);
      Answer now;
      make2(now, y, z, val);
      if (now < ans) ans = now;
    }
  }
  output(ans);
}
int calc(int x) {
  int ret = 0;
  while (x > 0) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
void test() {
  for (int i = 980; i <= 1010; ++i) {
    printf("%d %d\n", i, calc(i));
  }
}
int main() {
  int T;
  scanf("%d", &T);
  for (int cs = 1; cs <= T; ++cs) {
    solve();
  }
  return 0;
}
