#include <bits/stdc++.h>
using namespace std;
long long g(int n) {
  bool first = 1;
  long long res = 0;
  long long mul = 1;
  while (n) {
    int v = min(first ? 8 : 9, n);
    res += mul * v;
    n -= v;
    first = 0;
    mul *= 10;
  }
  return res;
}
const int M = 18;
const long long inf = 1e18;
long long solve(int a, int b, int n) {
  int top = 0;
  long long mul = 1;
  long long res = 1e18;
  for (int i = 0; i < M; ++i) {
    int dem = a + b;
    int num = n - b - a * top;
    if (num >= 0 && num % dem == 0) {
      long long tans = g(num / dem);
      tans *= mul;
      tans += mul - 1;
      res = min(res, tans);
    }
    top += 9;
    mul *= 10;
  }
  return res;
}
long long ans(int n, int k) {
  long long res = inf;
  for (int i = 0; i < 10; ++i) {
    int a = 0, b = 0;
    int tsum = 0;
    for (int j = 0; j < k + 1; ++j) {
      if (i + j >= 10)
        ++b;
      else
        ++a;
      tsum += (i + j) % 10;
    }
    long long tans = solve(a, b, n - tsum);
    if (tans != inf) tans = 10 * tans + i;
    res = min(res, tans);
  }
  if (res == inf) res = -1;
  return res;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    cout << ans(n, k) << '\n';
  }
}
