#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int ans = inf;
  for (long long int i = 0; i < 10; ++i) {
    long long int s1 = 0LL;
    for (long long int j = 0; j < (k + 1); ++j) s1 += (i + j) % 10;
    if (i + k >= 10) {
      for (long long int j = 0; j < 18; ++j) {
        long long int s2 = 9 * j * (10 - i);
        for (long long int l = 0; l < 9; ++l) {
          long long int s3 = s2 + (l + 1) * (k + i - 9) + l * (10 - i);
          if (n - s3 - s1 < 0) continue;
          if ((n - s3 - s1) % (k + 1) == 0) {
            long long int n1 = ((n - s3 - s1) / (k + 1)) % 9;
            for (long long int o = 0; o < ((n - s3 - s1) / (k + 1)) / 9; ++o)
              n1 = n1 * 10 + 9LL;
            n1 = n1 * 10 + l;
            for (long long int o = 0; o < j; ++o) n1 = n1 * 10 + 9LL;
            n1 = n1 * 10 + i;
            ans = min(ans, n1);
          }
        }
      }
    } else if ((n - s1) % (k + 1) == 0 && n - s1 >= 0) {
      long long int n1 = ((n - s1) / (k + 1)) % 9LL;
      for (long long int o = 0; o < ((n - s1) / (k + 1)) / 9LL; ++o)
        n1 = n1 * 10 + 9LL;
      n1 = n1 * 10 + i;
      ans = min(ans, n1);
    }
  }
  if (ans != inf)
    cout << ans << "\n";
  else
    cout << -1LL << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
}
