#include <bits/stdc++.h>
using namespace std;
const int N = 151;
const int K = 10;
int res[N][K];
int dig_sum(int x) {
  int result = 0;
  while (x) {
    result += x % 10;
    x /= 10;
  }
  return result;
}
void init() {
  for (int i = 0; i < N; i++) {
    for (int k = 0; k < K; k++) {
      res[i][k] = -1;
    }
  }
  for (int k = 1; k < 10; k++) {
    int cur = 0;
    for (int i = 0; i <= k; i++) {
      cur += dig_sum(i);
    }
    if (cur < N)
      if (res[cur][k] == -1) {
        res[cur][k] = 0;
      }
    int _upper = 100000;
    if (k < 3) {
      _upper *= 10;
    }
    for (int x = 1; x < _upper; x++) {
      cur -= dig_sum(x - 1);
      cur += dig_sum(x + k);
      if (cur < N)
        if (res[cur][k] == -1) {
          res[cur][k] = x;
        }
    }
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  int base_n = n;
  if (k > 1)
    cout << res[n][k] << "\n";
  else {
    if (k == 0) {
      string result;
      while (n > 9) {
        result += '9';
        n -= 9;
      }
      if (n > 0) result += '0' + n;
      reverse(result.begin(), result.end());
      cout << result << "\n";
    } else {
      if (res[n][k] != -1) {
        cout << res[n][k] << "\n";
      } else {
        string result;
        if (n % 2 == 1) {
          result += "89";
          n -= 8;
          n -= 9;
          n -= 9;
          n -= 9;
          n /= 2;
          while (n > 9) {
            result += '9';
            n -= 9;
          }
          if (n > 0) result += n + '0';
          if (n < 0) result = "1-";
          reverse(result.begin(), result.end());
          cout << result << "\n";
        } else {
          result += "98";
          n -= 8;
          n -= 9;
          n -= 9;
          n /= 2;
          while (n > 9) {
            result += '9';
            n -= 9;
          }
          if (n > 0) result += n + '0';
          if (n < 0) result = "1-";
          reverse(result.begin(), result.end());
          cout << result << "\n";
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  init();
  while (t--) {
    solve();
  }
  return 0;
}
