#include <bits/stdc++.h>
using namespace std;
template <typename T>
void prn(T first) {
  cout << first << "\n";
}
template <typename T, typename... Args>
void prn(T first, Args... args) {
  cout << first << " ";
  prn(args...);
}
const long long mx = 1e18;
long long sod(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
long long calc(long long sum) {
  if (sum == 0) return 0;
  long long l9 = sum / 9, rem = sum % 9;
  string s(l9, '9');
  if (rem > 0) {
    s += "8";
    s[0] -= (8 - rem);
  } else {
    if (!s.empty()) s.pop_back();
    s += "8";
    s = "1" + s;
  }
  return stoll(s);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j, t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    long long ans = mx;
    for (int last = 0; last <= 9; last++) {
      long long tens = 1;
      for (int trailing = 0; trailing <= 16; trailing++) {
        long long num = (tens - 1) * 10 + last;
        long long left = n - (sod(num) * (k + 1) + (k * (k + 1)) / 2 -
                              (trailing + 1) * 9 * max(0LL, k - (9 - last)));
        if (left >= 0 and left % (k + 1) == 0)
          ans = min(ans, calc(left / (k + 1)) * tens * 10 + num);
        tens *= 10;
      }
    }
    if (ans == mx) ans = -1;
    cout << ans << '\n';
  }
  return 0;
}
