#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int f(int x, int k) {
  int dr = 0;
  for (int i = 0; i <= k; ++i) {
    dr += (x + i) % 10;
  }
  return dr;
}
int S(int n, int x, int m, int k, int fx) {
  int dr;
  if (x + k >= 10) {
    dr = n - x - k + 9 - 9 * m * (10 - x) - fx;
  } else {
    dr = n - 9 * m * (k + 1) - fx;
  }
  if (dr < 0) return -1;
  if (dr % (k + 1))
    return inf;
  else
    return dr / (k + 1);
}
int Z(int s) {
  if (s <= 8) return 1;
  s -= 8;
  return s / 9 + !!(s % 9) + 1;
}
int P(int s) {
  if (s <= 8) return s;
  s = (s - 8) % 9;
  return (s ? s : 9);
}
string L(int s) {
  string dr = "";
  if (s == 0) return dr;
  dr += P(s) + '0';
  if (s <= 8) return dr;
  s -= P(s);
  while (s >= 9) {
    dr += '9';
    s -= 9;
  }
  dr += '8';
  return dr;
}
string R(int s, int m, int x) {
  string dr = L(s);
  for (int i = 0; i < m; ++i) dr += '9';
  dr += x + '0';
  return dr;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int ti = 1; ti <= t; ++ti) {
    int n, k;
    pair<pair<int, int>, pair<int, int> > fp = {{inf, 0}, {0, 0}};
    cin >> n >> k;
    for (int x = 0; x <= 9; ++x) {
      int fx = f(x, k), s;
      for (int m = 0; (s = S(n, x, m, k, fx)) >= 0; ++m) {
        if (s != inf) {
          fp = min(fp, {{Z(s) + m + 1, P(s)}, {m, x}});
        }
      }
    }
    string s = "-1";
    if (fp.first.first != inf) {
      s = R(S(n, fp.second.second, fp.second.first, k, f(fp.second.second, k)),
            fp.second.first, fp.second.second);
    }
    cout << s + "\n";
  }
  return 0;
}
