#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 2 * 1e18 + 7;
const int base = 2e5 + 1;
const int MAX = 1e5 + 2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 2 * 1e5 + 1;
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 1)
    return (binpow(a, n - 1) * a) % MOD;
  else {
    long long b = binpow(a, n / 2) % MOD;
    return (b * b) % MOD;
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long tt;
  cin >> tt;
  vector<int> f = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  for (long long kk = (0); kk < (tt); ++kk) {
    int n, k;
    long long res = INF;
    cin >> n >> k;
    for (long long i = (0); i < (10); ++i) {
      long long cur = 0;
      for (long long j = (0); j < (k + 1); ++j) {
        cur += f[i + j];
      }
      long long t = i;
      long long n1 = n - cur;
      if (n1 < 0 || (n1 % (k + 1) != 0)) {
        continue;
      }
      n1 /= k + 1;
      if (i + k >= 10) {
        t += 10 * min(8ll, n1);
      } else {
        t += 10 * min(9ll, n1);
        n1--;
      }
      n1 -= 8;
      long long mult = 100;
      while (n1 > 0) {
        t += mult * min(9ll, n1);
        n1 -= 9;
        mult *= 10;
      }
      res = min(res, t);
    }
    cout << (res == INF ? -1 : res) << '\n';
  }
  return 0;
}
