#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  time_t tic, toc;
  long long int tt = 1, n, m, k = 0, i, j, p, q;
  long long int a, b, h, w, u, v, x, y;
  long long int l = 0, r = 0;
  long long int ans = 0;
  bool poss = true;
  string s, t, tmp;
  cin >> tt;
  tic = clock();
  for (int _ = 1; _ <= tt; _++) {
    cin >> n >> k;
    poss = false;
    t = "9999999999999999999999";
    s = "";
    for (i = 0; i < 10; i++) {
      for (j = 0; j < 18; j++) {
        s = '0' + i;
        s.append(j, '9');
        long long int pos = min(k, 9 - i);
        long long int rem = k - pos;
        long long int rem_sum = n - pos * (pos + 1) / 2 - rem * (rem + 1) / 2 -
                                (9 * j + i) * (pos + 1);
        if (rem_sum < 0) continue;
        if (rem_sum % (pos + rem + 1) != 0) continue;
        rem_sum /= (pos + rem + 1);
        tmp = "";
        while (rem_sum > 9) {
          tmp += '9';
          rem_sum -= 9;
        }
        if (rem_sum == 9) {
          tmp = '1' + tmp + '8';
        } else if ((long long int)(tmp).size() == 0 and rem_sum > 0) {
          tmp += '0' + rem_sum;
        } else if ((long long int)(tmp).size() and rem_sum > 0) {
          tmp.pop_back();
          char c = '0' + rem_sum + 1, d = '8';
          tmp = c + tmp + d;
        }
        reverse(s.begin(), s.end());
        tmp += s;
        if ((long long int)(tmp).size() < (long long int)(t).size()) {
          t = tmp;
        } else if ((long long int)(t).size() == (long long int)(tmp).size())
          t = min(t, tmp);
        poss = true;
      }
    }
    if (poss)
      cout << t << "\n";
    else
      cout << -1 << "\n";
  }
  return 0;
}
