#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
const int maxx = 1e6 + 100;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  while (b ^= a ^= b ^= a %= b)
    ;
  return a;
}
int fa[300];
void init() {
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= i; j++) {
      fa[i] += j;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  init();
  int a;
  cin >> a;
  while (a--) {
    stack<int> q;
    int n, k;
    bool flag = false;
    cin >> n >> k;
    int turn = k + 1, rest = 100;
    int vis = -1;
    if (n - fa[k] < 0) {
      cout << -1 << endl;
      continue;
    }
    if ((n - fa[k]) % turn == 0) {
      rest = (n - fa[k]) / turn;
      vis = 0;
    }
    for (int i = 1; i <= 9; i++) {
      int sum = i, pre = i;
      bool biaoji = false;
      for (int j = 1; j <= k; j++) {
        pre++;
        if (pre > 9) {
          pre = 1;
          biaoji = true;
        }
        sum += pre;
      }
      if (n >= sum && (n - sum) % turn == 0 && (n - sum) / turn < rest) {
        rest = (n - sum) / turn;
        vis = i;
        flag = biaoji;
      }
    }
    if (vis == -1) {
      cout << -1 << endl;
      continue;
    }
    q.push(vis);
    while (rest) {
      if (flag && rest > 8 && q.size() == 1) {
        rest -= 8;
        q.push(8);
      } else {
        q.push(min(9, rest));
        rest -= min(9, rest);
      }
    }
    while (q.size()) {
      cout << q.top();
      q.pop();
    }
    cout << endl;
  }
  return 0;
}
