#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  int a = n + k * (k + 1) / 2;
  if (a % (k + 1) == 0) {
    n = n + k * (k + 1) / 2;
    n /= (k + 1);
    long long num = n % 9;
    for (int i = 0; i < n / 9; i++) {
      num *= 10;
      num += 9;
    }
    num -= k;
    if (num >= 0) {
      printf("%lld\n", num);
      return;
    }
  }
  long long ans = 1e18;
  int holdn = n;
  for (int d = 0; d < k; d++) {
    n = holdn;
    int initial = (d * (d + 1)) / 2;
    initial += 9 * (k - d) - ((k - d) * (k - d - 1)) / 2;
    if (n - initial < 0) continue;
    n -= initial;
    for (int tz = 0; tz < 10; tz++) {
      long long m = n + (k - d) * (1 - 9 * tz);
      if (m < 0) continue;
      if (m % (k + 1) != 0) continue;
      m /= (k + 1);
      long long num = m % 9;
      for (int i = 0; i < m / 9; i++) {
        num *= 10;
        num += 9;
      }
      for (int i = 0; i < tz; i++) {
        num *= 10;
      }
      num = num * 10 + d - k;
      if (num < 0) continue;
      ans = min(ans, num);
    }
  }
  if (ans == 1e18) ans = -1;
  printf("%lld\n", ans);
  return;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
