#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long construct(int n) {
  long long res = 0;
  if (n < 8) {
    return n;
  }
  n -= 8;
  res += n % 9;
  n -= n % 9;
  while (n) {
    res *= 10;
    res += min(n, 9);
    n -= min(n, 9);
  }
  res = (res * 10) + 8;
  return res;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long ans = LLONG_MAX;
    long long pow = 1;
    for (int n9 = 0; n9 <= 16; n9++) {
      pow *= 10;
      for (int d = 0; d < 10; d++) {
        int no_carry = min(10 - d, k + 1);
        int find = n - n9 * 9 * no_carry - (k + 1 - no_carry);
        for (int i = 0; i <= k; i++) {
          find -= (i + d) % 10;
        }
        if (find >= 0 && find % (k + 1) == 0) {
          ans = min(ans, pow * construct(find / (k + 1)) + pow - 10 + d);
        }
      }
    }
    if (ans == LLONG_MAX)
      cout << -1;
    else
      cout << ans;
    cout << '\n';
  }
}
