#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  string minx;
  for (int i = (1); i <= (100); ++i) minx.push_back('9');
  bool gotmin = 0;
  for (int d = (0); d <= (9); ++d)
    for (int nines = (0); nines <= (16); ++nines) {
      int type1 = min(10 - d, k + 1);
      int num = n - type1 * (9 * nines - 1);
      for (int i = (0); i <= (k); ++i) num -= (d + i) % 10;
      int den = k + 1;
      if (num % den || num < den) continue;
      int fp = num / den - 1;
      string x;
      x.push_back(d + 48);
      for (int i = (1); i <= (nines); ++i) x.push_back('9');
      int test = 8;
      while (fp) {
        int pull = min(fp, test);
        fp -= pull;
        x.push_back(pull + 48);
        test = 9;
      }
      if (x.size() < minx.size())
        minx = x, gotmin = 1;
      else if (x.size() == minx.size())
        for (int i = (minx.size() - 1); i >= (0); --i) {
          if (x[i] == minx[i]) continue;
          if (x[i] < minx[i]) {
            minx = x;
            gotmin = 1;
          }
          break;
        }
    }
  if (!gotmin)
    cout << -1;
  else
    for (int i = (minx.size() - 1); i >= (0); --i) cout << minx[i];
  cout << endl;
}
int main() {
  int t;
  for (cin >> t; t--; solve())
    ;
}
