#include <bits/stdc++.h>
using namespace std;
const int MAX = 200010;
const long long INF = 1e12;
int k;
int dp[33][155];
int dsum(long long num) {
  int ret = 0;
  while (num) {
    ret += num % 10;
    num /= 10;
  }
  return ret;
}
int call(int pos, int baki) {
  if (baki < 0) return 0;
  if (pos == 0) return (baki == 0);
  if (dp[pos][baki] != -1) return dp[pos][baki];
  int ret = 0;
  if (pos == 2) {
    for (int i = 0; i < 100; i++) {
      int sum = 0;
      for (int j = 0; j <= k; j++) sum += dsum(i + j);
      if (sum == baki) {
        ret = i;
        break;
      }
    }
  } else {
    for (int i = 0; i <= 9; i++) {
      ret |= call(pos - 1, baki - i * (k + 1));
      if (ret) break;
    }
  }
  return dp[pos][baki] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    int n;
    cin >> n >> k;
    memset(dp, -1, sizeof(dp));
    int go = -1;
    for (int i = 0; i < 100; i++) {
      int sum = 0;
      for (int j = 0; j <= k; j++) sum += dsum(i + j);
      if (sum == n) {
        go = i;
        break;
      }
    }
    if (go != -1) {
      cout << go << '\n';
      continue;
    }
    int len = -1;
    for (int i = 3; i <= 30; i++) {
      if (call(i, n)) {
        len = i;
        break;
      }
    }
    if (len == -1) {
      cout << -1 << '\n';
    } else {
      string ans = "";
      int baki = n;
      int last = 99;
      for (int i = 1; i <= len - 2; i++) {
        for (int j = 0; j <= 9; j++) {
          last = call(len - i, baki - (k + 1) * j);
          if (last) {
            ans += (char)(j + '0');
            baki -= (k + 1) * j;
            break;
          }
        }
      }
      cout << ans;
      if (last <= 9) cout << 0;
      cout << last << '\n';
    }
  }
  return 0;
}
