#include <bits/stdc++.h>
using namespace std;
long long fit0(int num) {
  if (num <= 9) return num;
  vector<int> res;
  res.push_back(9);
  num -= 9;
  while (num > 0) {
    if (num >= 9) {
      num -= 9;
      res.push_back(9);
    } else {
      res.push_back(num);
      num = 0;
    }
  }
  long long T = 0;
  reverse(res.begin(), res.end());
  for (int i = 0; i < res.size(); ++i) {
    T *= 10;
    T += res[i];
  }
  return T;
}
long long fit1(int num) {
  if (num <= 8) return num;
  vector<int> res;
  res.push_back(8);
  num -= 8;
  while (num > 0) {
    if (num >= 9) {
      num -= 9;
      res.push_back(9);
    } else {
      res.push_back(num);
      num = 0;
    }
  }
  long long T = 0;
  reverse(res.begin(), res.end());
  for (int i = 0; i < res.size(); ++i) {
    T *= 10;
    T += res[i];
  }
  return T;
}
void solve() {
  int n, k;
  cin >> n >> k;
  int c[10];
  bool carry[10];
  for (int i = 0; i < 10; ++i) {
    c[i] = 0;
    for (int j = 0; j <= k; ++j) {
      c[i] += ((i + j) % 10 + (i + j) / 10);
    }
    if (i + k >= 10)
      carry[i] = true;
    else
      carry[i] = false;
  }
  long long ans = -1;
  for (int i = 0; i < 10; ++i) {
    if ((n - c[i]) % (k + 1) == 0) {
      int d = (n - c[i]) / (k + 1);
      if (d < 0) continue;
      long long num;
      if (carry[i]) {
        long long pod = fit1(d);
        num = pod * 10 + i;
      } else {
        long long pod = fit0(d);
        num = pod * 10 + i;
      }
      if (ans == -1)
        ans = num;
      else
        ans = min(ans, num);
    }
  }
  if (ans == -1) {
    cout << -1 << "\n";
    return;
  }
  cout << ans << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
