#include <bits/stdc++.h>
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
int n, m, k;
int a[maxn], b[maxn];
char s[maxn];
void solve() {
  scanf("%d%d", &n, &k);
  k++;
  for (int i = 1; i <= 500; i++) {
    string ans = "";
    for (int j = 0; j < i; j++) {
      for (int l = 0; l <= 9; l++) {
        int fir = min(k, 10 - l), sec = k - fir;
        int mid = fir * 9 * j,
            suf = (l + l + fir - 1) * fir / 2 + (0 + sec - 1) * sec / 2;
        if (mid + suf > n) continue;
        int pre = n - mid - suf;
        if (pre < sec || (pre - sec) % k != 0) continue;
        int num = i - j - 1, x = (pre - sec) / k;
        string tmp = "";
        if (num > 1 && num * 9 <= x) continue;
        if (!num && x) continue;
        if (num == 1 && x >= 9) continue;
        if (x >= 9) {
          tmp += to_string(8), x -= 8;
          while (x) {
            if (x >= 9)
              tmp += to_string(9), x -= 9;
            else if (x > 0)
              tmp += to_string(x), x = 0;
          }
        } else if (x > 0)
          tmp += to_string(x);
        reverse(tmp.begin(), tmp.end());
        for (int a = 0; a < j; a++) tmp += to_string(9);
        tmp += to_string(l);
        if (ans == "" || ans > tmp) ans = tmp;
      }
    }
    if (ans != "") {
      printf("%s\n", ans.c_str());
      return;
    }
  }
  printf("-1\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
