#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template <typename... T>
void rd(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void wr(T... args) {
  ((cout << args << " "), ...);
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    k++;
    ll mn = 1e18;
    for (int last = 0; last < 10; last++) {
      for (int count9 = 0; count9 < 15; count9++) {
        int c1 = k, c2 = 0;
        if (last + k - 1 > 9) {
          c1 = 10 - last;
          c2 = k - c1;
        }
        int need = n - (count9 * 9 * c1 + (last * 2 + c1 - 1) * c1 / 2 + c2 +
                        (c2 - 1) * c2 / 2);
        if (need < 0 || need % k) continue;
        need /= k;
        ll ans = 0, base = 1;
        int is_first = 1;
        while (need) {
          ans += min(need, is_first && c2 ? 8 : 9) * base;
          base *= 10;
          need -= min(need, is_first && c2 ? 8 : 9);
          is_first = 0;
        }
        for (int i = 0; i < int(count9); ++i) ans = ans * 10 + 9;
        if (last == 0 && k == 1 && ans)
          ;
        else
          ans = ans * 10 + last;
        mn = min(mn, ans);
      }
    }
    if (mn == 1e18)
      cout << -1 << endl;
    else
      cout << mn << endl;
  }
  return 0;
}
