#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool f) {
  if (f)
    return "True";
  else
    return "False";
}
string to_string(const char *s) { return to_string((string)s); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = false;
  string r = "{";
  for (auto x : v) {
    if (f) r += ", ";
    r += to_string(x);
    f = true;
  }
  return r += "}";
}
template <typename A>
string to_string(vector<vector<A>> v) {
  string r;
  for (auto x : v) r += "\n" + to_string(x);
  return r;
}
long long Nerr;
template <typename A>
string to_string(A *p) {
  return to_string(vector<A>(p, p + Nerr));
}
void err(istream_iterator<string>) { cerr << '\n'; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; ";
  err(++it, args...);
}
template <typename T>
void kek(T ans) {
  cout << ans << '\n';
  exit(0);
}
string findSum(string str1, string str2) {
  if (str1.length() > str2.length()) swap(str1, str2);
  string str;
  long long n1 = str1.length(), n2 = str2.length();
  reverse(str1.begin(), str1.end());
  reverse(str2.begin(), str2.end());
  long long carry = 0;
  for (long long i = 0; i < n1; i++) {
    long long sum = ((str1[i] - '0') + (str2[i] - '0') + carry);
    str.push_back(sum % 10 + '0');
    carry = sum / 10;
  }
  for (long long i = n1; i < n2; i++) {
    long long sum = ((str2[i] - '0') + carry);
    str.push_back(sum % 10 + '0');
    carry = sum / 10;
  }
  if (carry) str.push_back(carry + '0');
  reverse(str.begin(), str.end());
  return str;
}
signed main() {
  ios_base::sync_with_stdio(0);
  long long TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long n, k;
    cin >> n >> k;
    string ans;
    for (long long a1 = 0; a1 < 10; a1++) {
      for (long long a2 = 0; a2 < 10; a2++) {
        long long sum = 0;
        string c;
        c.push_back(a2 + '0');
        c.push_back(a1 + '0');
        for (long long i = 0; i < k + 1; i++) {
          string t;
          t.push_back('0' + i);
          string r = findSum(t, c);
          for (auto j : r) sum += j - '0';
        }
        if (sum > n) continue;
        long long left = (n - sum);
        if (left % (k + 1)) continue;
        left /= (k + 1);
        string temp;
        while (left) {
          long long add = min(9ll, left);
          left -= add;
          temp.push_back('0' + add);
        }
        reverse((temp).begin(), (temp).end());
        temp.push_back('0' + a2);
        temp.push_back('0' + a1);
        reverse((temp).begin(), (temp).end());
        while (temp.back() == '0') {
          temp.pop_back();
        }
        reverse((temp).begin(), (temp).end());
        if ((long long)temp.size() == 0) temp = "0";
        if ((long long)ans.size() == 0)
          ans = temp;
        else {
          if ((long long)temp.size() < (long long)ans.size())
            ans = temp;
          else if ((long long)temp.size() == (long long)ans.size())
            ans = min(ans, temp);
        }
      }
    }
    if ((long long)ans.size() == 0)
      cout << -1 << '\n';
    else
      cout << ans << '\n';
  }
}
