#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long best = 8e18;
    for (int m = 1; m <= 18; ++m) {
      for (int x = 0; x <= 9; ++x) {
        int sum = 0;
        for (int i = 0; i <= k; ++i) sum += (x + i) % 10;
        if (x + k <= 9) {
          int rest = n - sum;
          if (rest >= 0 && (rest % (k + 1) == 0) &&
              (rest / (k + 1) <= 9 * (m - 1))) {
            if (m == 1 || rest >= k + 1) {
              vector<int> ans;
              ans.push_back(x);
              int digleft = m - 1;
              rest /= (k + 1);
              while (digleft > 1 && rest >= 10)
                ans.push_back(9), digleft--, rest -= 9;
              if (digleft > 1) ans.push_back(rest - 1), digleft--;
              while (digleft > 1) ans.push_back(0), digleft--;
              if (digleft) ans.push_back(rest);
              long long cur = 0ll;
              for (int i = 0; i < ans.size(); ++i)
                cur *= 10, cur += ans[ans.size() - 1 - i];
              best = min(best, cur);
            }
          }
        } else
          for (int s = 1; s <= m - 1; ++s) {
            for (int y = 0; y <= 8; ++y) {
              int rest = n - ((10 - x) * (9 * (s - 1) + y) +
                              (k + 1 - 10 + x) * (y + 1) + sum);
              if (rest >= 0 && (rest % (k + 1) == 0) &&
                  (rest / (k + 1) <= 9 * (m - s - 1))) {
                if (s == m - 1 || rest >= k + 1) {
                  vector<int> ans;
                  ans.push_back(x);
                  for (int i = 0; i < s - 1; ++i) ans.push_back(9);
                  ans.push_back(y);
                  int digleft = m - s - 1;
                  rest /= (k + 1);
                  while (digleft > 1 && rest >= 10)
                    ans.push_back(9), digleft--, rest -= 9;
                  if (digleft > 1) ans.push_back(rest - 1), digleft--;
                  while (digleft > 1) ans.push_back(0), digleft--;
                  if (digleft) ans.push_back(rest);
                  long long cur = 0ll;
                  for (int i = 0; i < ans.size(); ++i)
                    cur *= 10, cur += ans[ans.size() - 1 - i];
                  best = min(best, cur);
                }
              }
            }
          }
      }
    }
    if (best == 8e18)
      cout << -1 << endl;
    else
      cout << best << endl;
  }
}
