#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int znam[20];
int n, k;
long long naj(int x) {
  long long sol = 0;
  if (9 - k + 1 > x) {
    sol = x;
    x -= x;
  } else {
    sol = 9 - k + 1;
    x -= 9 - k + 1;
  }
  long long pot = 10;
  while (x) {
    if (x > 9) {
      sol += pot * 9;
      x -= 9;
    } else {
      sol += pot * x;
      x -= x;
    }
    pot *= 10;
  }
  return sol;
}
long long resi(int x, int y, int z) {
  long long sol = 0;
  long long pot = 10;
  sol = 9 - z + 1;
  x -= 9 - z + 1;
  for (int i = 1; i < y; i++) {
    sol += pot * 9;
    pot *= 10;
    x -= 9;
  }
  if (x < 0) {
    return inf;
  }
  if (x > 8) {
    sol += pot * 8;
    pot *= 10;
    x -= 8;
  } else {
    sol += pot * x;
    x -= x;
  }
  while (x) {
    if (x > 9) {
      sol += pot * 9;
      x -= 9;
    } else {
      sol += pot * x;
      x -= x;
    }
    pot *= 10;
  }
  return sol;
}
long long rijesi(int x) {
  long long res;
  long long m = n;
  res = inf;
  if (x == k) {
    if (m % k == 0) {
      res = naj(m / k);
    }
    return res;
  }
  for (int i = 1; i < 17; i++) {
    m = n + znam[i] * (k - x);
    if (m % k == 0) {
      res = min(res, resi(m / k, i, x));
    }
  }
  return res;
}
void solve() {
  cin >> n >> k;
  k++;
  if ((k - 1) * k / 2 > n) {
    cout << -1 << '\n';
    return;
  }
  n -= (k - 1) * k / 2;
  long long sol = inf;
  for (int i = 1; i <= k; i++) {
    sol = min(sol, rijesi(i));
  }
  if (sol == inf) {
    cout << -1 << '\n';
  } else {
    cout << sol << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < 20; i++) {
    znam[i] = i * 9;
  }
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
