#include <bits/stdc++.h>
using namespace std;
class TaskE {
  int n, k;
  string res;
  void checkMinimum(int prefix, int next, int nines, int lastDigit) {
    string cur = "";
    cur += (lastDigit + '0');
    for (int i = 0; i < nines; i++) cur += '9';
    cur += (next + '0');
    while (prefix >= 9) {
      cur += '9';
      prefix -= 9;
    }
    cur += (prefix + '0');
    while (cur.size() > 1 and cur.back() == '0') cur.pop_back();
    reverse(cur.begin(), cur.end());
    if ((res.empty()) or (cur.size() < res.size()) or
        (cur.size() == res.size() and cur < res)) {
      res = cur;
    }
  }

 public:
  TaskE(int n, int k) {
    this->n = n;
    this->k = (k + 1);
  }
  string solve() {
    for (int lastDigit = 0; lastDigit <= 9; lastDigit++) {
      for (int nines = 0; 9 * nines <= n; nines++) {
        for (int next = 0; next < 9; next++) {
          int sum = 0;
          int curLastDigit = lastDigit;
          int cur = lastDigit + (9 * nines) + next;
          for (int j = 0; j < k; j++) {
            sum += cur;
            cur++, curLastDigit++;
            if (curLastDigit == 10) {
              cur -= 9 * (nines + 1);
            }
          }
          if (sum <= n and (n - sum) % k == 0) {
            int prefix = (n - sum) / k;
            checkMinimum(prefix, next, nines, lastDigit);
          }
        }
      }
    }
    if (res.empty()) res = "-1";
    return res;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    TaskE E(n, k);
    string res = E.solve();
    cout << res << '\n';
  }
}
