#include <bits/stdc++.h>
using namespace std;
long long st = 0, pw = 1;
int n, k;
vector<long long> dig;
int digsum(long long n) {
  int sum = 0;
  for (; n; sum += n % 10, n /= 10)
    ;
  return sum;
}
int main() {
  for (int i = 0; i < 18; ++i) {
    if (i) pw *= 10;
    for (int j = 0; j < 9; ++j) dig.push_back(pw * (j + 1) + st);
    st = dig.back();
  }
  int Case;
  scanf("%d", &Case);
  while (Case--) {
    scanf("%d%d", &n, &k);
    int p = n / (k + 1), sum = 0;
    long long ans = 0;
    for (int w = -1; w < 120; ++w) {
      for (int i = -100; i <= 9; ++i) {
        sum = 0;
        ans = dig[p + w] + i;
        for (int j = 0; j <= k; ++j) sum += digsum(ans + j);
        if (sum == n) break;
      }
      if (sum == n) break;
    }
    if (sum != n || ans < 0) ans = -1;
    printf("%lld\n", ans);
  }
  return 0;
}
