#include <bits/stdc++.h>
using namespace std;
int n, m;
int getsum(long long x) {
  int res = 0;
  for (int i = 0; i <= m; i++) {
    long long num = x + i;
    while (num > 0) {
      res += num % 10;
      num /= 10;
      if (res > n) return n + 1;
    }
  }
  return res;
}
int main() {
  int q;
  scanf("%d", &q);
  for (int times = 1; times <= q; times++) {
    scanf("%d%d", &n, &m);
    long long pow = 100, sum = 0, ans = 1ll << 60;
    for (int i = 0; i <= 99; i++)
      if (getsum(i) == n) ans = min(ans, 1ll * i);
    for (int i = 0; i <= n / 9 - 1; i++) {
      for (int j = 1; j <= 9; j++) {
        for (int k = 0; k <= 9; k++)
          for (int l = 0; l <= 9; l++) {
            if (getsum(pow * j + sum + k * 10 + l) == n) {
              ans = min(ans, pow * j + sum + k * 10 + l);
            }
          }
      }
      sum += pow * 9;
      pow *= 10;
      if (getsum(pow + sum) > n) break;
    }
    if (ans == (1ll << 60))
      puts("-1");
    else
      printf("%lld\n", ans);
  }
  return 0;
}
