#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int n;
int k;
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    long long res = -1;
    for (int i = 0; i <= 9; i++) {
      int rem = n - (2 * i + k) * (k + 1) / 2;
      if (i + k > 9) rem += (i + k - 9) * 9;
      if (rem >= 0 && rem % (k + 1) == 0) {
        rem /= (k + 1);
        long long ts = 0, bas = 1;
        while (rem > 0) {
          int d;
          if (bas == 1 && i + k > 9)
            d = min(rem, 8);
          else
            d = min(rem, 9);
          ts = ts + 1ll * d * bas;
          rem -= d;
          bas = bas * 1ll * 10;
        }
        ts = ts * 1ll * 10 + 1ll * i;
        if (res == -1)
          res = ts;
        else
          res = min(res, ts);
      }
    }
    cout << res << "\n";
  }
  return 0;
}
