#include <bits/stdc++.h>
using namespace std;
string part1(int a) {
  int ini = a;
  string ret;
  if (a >= 8) {
    ret += '8';
    a -= 8;
  }
  while (a >= 9) {
    a -= 9;
    ret += '9';
  }
  for (int i = 1; i <= 8; i++) {
    if (a == i) ret += (char)((int)'0' + i);
  }
  if (false) {
    cout << "tentando chegar na soma " << ini << " ret = " << ret << "\n";
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
string infs() {
  string a;
  for (int i = 0; i < 152; i++) a += '9';
  return a;
}
string meno(string a, string b) {
  if (a.size() < b.size())
    return a;
  else if (b.size() < a.size())
    return b;
  if (a < b) return a;
  return b;
}
string complete(int q9, int dig) {
  string ret;
  for (int i = 0; i < q9; i++) ret += '9';
  ret += (char)((int)'0' + dig);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string rr;
    rr = infs();
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j <= 9; j++) {
        string resp = "";
        int sover, cover, s = 0;
        sover = min(10 - j, k + 1);
        cover = k + 1 - sover;
        for (int aux = 0; aux < k + 1; aux++) s += (j + aux) % 10;
        int falta = n - (sover * 9 * i) - s;
        if (false) {
          cout << "sover = " << sover << " cover = " << cover << "\n";
          cout << "falta = " << falta << "\n";
          int x = (falta - cover) / (sover + cover);
          cout << "x = " << x << "\n";
          cout << "parte 1 " << part1(x) << "\n";
        }
        if ((falta - cover) >= 0 and ((falta - cover) % (sover + cover) == 0)) {
          int x = (falta - cover) / (sover + cover);
          resp = part1(x) + complete(i, j);
          rr = meno(resp, rr);
        }
      }
    }
    if (rr == infs())
      cout << -1 << "\n";
    else
      cout << rr << "\n";
  }
}
