#include <bits/stdc++.h>
using namespace std;
string precal(int ps) {
  string ans = "99999999999999999999999999999999";
  for (int d = 0; d < min(9, ps + 1); d++) {
    string g = "";
    int x = ps - d;
    g.push_back(d + '0');
    int q = x / 9;
    while (q--) g.push_back('9');
    q = x % 9;
    if (q > 0) g.push_back('0' + q);
    reverse(g.begin(), g.end());
    if (g.size() < ans.size())
      ans = g;
    else if (g.size() == ans.size() && g < ans)
      ans = g;
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string ans = "9999999999999999999999999999999999999999999999";
    string cans = ans;
    if (k == 0) {
      ans = "";
      int q = n / 9;
      while (q--) ans.push_back('9');
      q = n % 9;
      if (q > 0) ans.push_back('0' + q);
      reverse(ans.begin(), ans.end());
    } else {
      for (int d = 0; d < 10; d++) {
        for (int q = 0; q <= 20; q++) {
          string tans = "";
          int l = min(k + 1, 10 - d);
          int m = k + 1 - l, lsum = 0;
          tans.push_back(d + '0');
          for (int i = 1; i <= q; i++) tans.push_back('9');
          for (int h = d; h < min(10, k + 1 + d); h++) lsum += h;
          for (int h = 1; h < m; h++) lsum += h;
          int x = n - l * 9 * q - m - lsum;
          if (x % (k + 1) == 0 && x >= 0) {
            if (x > 0) {
              int ps = (x / (k + 1));
              string g = precal(ps);
              reverse(g.begin(), g.end());
              tans = tans + g;
            }
            reverse(tans.begin(), tans.end());
            if (tans.size() <= ans.size()) {
              if (tans.size() < ans.size())
                ans = tans;
              else if (tans < ans && tans.size() == ans.size())
                ans = tans;
            }
          }
        }
      }
    }
    if (ans == cans) ans = "-1";
    cout << ans << "\n";
  }
}
