#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 239;
string proc(long long x) {
  string res;
  long long can = 0;
  while (x) {
    long long to = INF;
    if (!can) {
      to = min(x, (long long)8);
    } else {
      to = min(x, (long long)9);
    }
    can = 1;
    res.push_back('0' + to);
    x -= to;
  }
  reverse(res.begin(), res.end());
  return res;
}
long long solve(long long cnt_f, long long cnt_s, long long need) {
  long long ans = INF;
  for (long long cnt9 = 0; cnt9 < 16; cnt9++) {
    long long delta = -9 * cnt9 + 1;
    long long lp = (need - delta * cnt_s);
    if (lp < 0) continue;
    if (lp % (cnt_f + cnt_s)) continue;
    long long fx = (lp / (cnt_f + cnt_s));
    if (fx < 9 * cnt9) continue;
    string t = proc(fx - 9 * cnt9);
    for (long long i = 0; i < cnt9; i++) {
      t.push_back('9');
    }
    if (!t.empty())
      ans = min(ans, stoll(t));
    else
      ans = min(ans, (long long)0);
  }
  return ans;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long ans = INF;
  for (long long f = 0; f < 10; f++) {
    long long cnt_bef = 0;
    long long any = 0;
    long long c = f;
    long long s = 0;
    for (long long j = 0; j <= k; j++) {
      s += c;
      if (!any) cnt_bef++;
      c++;
      if (c == 10) {
        c = 0;
        any = 1;
      }
    }
    long long need = n - s;
    if (need < 0) continue;
    long long v = solve(cnt_bef, k + 1 - cnt_bef, n - s);
    if (v == INF) continue;
    ans = min(ans, v * 10 + f);
  }
  if (ans == INF) {
    cout << -1 << '\n';
  } else {
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    solve();
  }
}
