#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
long long nextLong() {
  long long x;
  scanf("%lld", &x);
  return x;
}
long long f(long long x) {
  long long res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main2() {
  int N = nextLong();
  int K = nextLong();
  if (K == 0) {
    string ans = "";
    while (N > 0) {
      int d = min(N, 9);
      ans = (char)('0' + d) + ans;
      N -= d;
    }
    cout << ans << '\n';
    return 0;
  }
  long long ans = -1;
  for (int n = 0; n <= 16; n++) {
    for (int l = 0; l <= 9; l++) {
      long long v = 0;
      for (int _ = 0, _n = (int)(n); _ < _n; ++_) v = v * 10 + 9;
      v = v * 10 + l;
      long long s = 0;
      for (int k = 0, _n = (int)(K + 1); k < _n; ++k) s += f(v + k);
      if (s > N) continue;
      int rem = N - s;
      if (rem % (K + 1)) continue;
      rem /= (K + 1);
      long long pre = 0;
      for (long long i = 0; rem > 0; i++) {
        int d = min(rem, (i == 0 ? 8 : 9));
        rem -= d;
        pre += pow(10, i) * d;
      }
      long long val = pre * pow(10, n + 1) + v;
      long long check = 0;
      for (int k = 0, _n = (int)(K + 1); k < _n; ++k) check += f(val + k);
      if (ans == -1 || ans > val) {
        ans = val;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
int main() {
  int t = nextLong();
  while (t--) main2();
  return 0;
}
