#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
inline int add(int a, int b) {
  a += b;
  return a >= 1000000007 ? a - 1000000007 : a;
}
inline int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + 1000000007 : a;
}
inline int mul(int a, int b) { return (long long int)a * b % 1000000007; }
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Cheek(int N, int pos) { return (bool)(N & (1 << pos)); }
long long int digitSum(long long int x) {
  long long int sum = 0;
  while (x) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}
bool isPossible(long long int start, long long int k, long long int n) {
  long long int tot = 0;
  for (long long int i = start; i <= start + k; i++) {
    tot += digitSum(i);
  }
  return (tot == n);
}
void Solve(int t) {
  long long int i, j, k, n, res = 9223372036854775800;
  scanf("%lld %lld", &(n), &(k));
  long long int koto = (n / (k + 1)) + (bool)(n % (k + 1));
  long long int koyta9 = koto / 9;
  for (long long int ekhn9 = max(0LL, koyta9 - 1); ekhn9 <= koyta9 + 1;
       ekhn9++) {
    for (long long int j = 0; j <= 9; j++) {
      long long int val = j;
      for (i = 1; i <= ekhn9; i++) {
        val *= 10;
        val += 9;
      }
      long long int start = max(0LL, val - 1000LL);
      for (i = start; i <= val + 1000; i++) {
        if (isPossible(i, k, n)) {
          res = min(res, i);
          break;
        }
      }
    }
  }
  if (res == 9223372036854775800)
    cout << "-1\n";
  else
    cout << res << endl;
}
int main() {
  int t, T;
  scanf("%d", &(T));
  for (__typeof(t) t = 1; t <= T; t++) {
    Solve(t);
  }
  return 0;
}
