#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
int tt, n, k, dig[20];
long long ans, res;
int main() {
  dig[0] = 0;
  for (int i = 1; i <= 9; ++i) {
    dig[i] = dig[i + 9] = i;
  }
  for (cin >> tt; tt--;) {
    ans = 1e18;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < 10; ++i) {
      int sum0 = 0;
      res = 0;
      for (int j = i; j <= i + k; ++j) sum0 += dig[j];
      if (n - sum0 < 0 || (n - sum0) % (k + 1)) continue;
      long long x = (n - sum0) / (k + 1);
      if (x < 9)
        res = x;
      else {
        int tmp = 8;
        if (i + k <= 9) tmp = 9;
        x -= tmp;
        res = x % 9;
        x -= res;
        while (x) res = res * 10 + 9, x -= 9;
        res = res * 10 + tmp;
      }
      res = res * 10 + i;
      if (res < ans) ans = res;
    }
    if (ans == 1e18)
      puts("-1");
    else
      cout << ans << endl;
  }
  return 0;
}
