#include <bits/stdc++.h>
using namespace std;
const long long inf = 1ll << 60;
long long digit(long long n) {
  long long sum = 0;
  for (; n; n /= 10) sum += n % 10;
  return sum;
}
long long f(long long x, long long k) {
  long long res = 0;
  for (long long i = 0; i <= k; i++) res += digit(x + i);
  return res;
}
long long ans[151][10];
void preProcess() {
  for (long long i = 0; i <= 150; i++)
    for (long long k = 0; k < 10; k++) ans[i][k] = inf;
  for (long long a = 0; a < 10; a++)
    for (long long b = 0; b < 16; b++)
      for (long long c = 0; b + c < 16; c++)
        for (long long d = 0; d < 10; d++) {
          long long x = a;
          for (long long i = 0; i < b; i++) x = x * 10 + 9;
          x = x * 10 + 8;
          for (long long i = 0; i < c; i++) x = x * 10 + 9;
          x = x * 10 + d;
          for (long long k = 0; k < 10; k++) {
            long long res = f(x, k);
            if (res <= 150) ans[res][k] = min(ans[res][k], x);
          }
        }
  for (long long a = 0; a < 10; a++)
    for (long long b = 0; b <= 16; b++)
      for (long long c = 0; c < 10; c++) {
        long long x = a;
        for (long long i = 0; i < b; i++) x = x * 10 + 9;
        x = x * 10 + c;
        for (long long k = 0; k < 10; k++) {
          long long res = f(x, k);
          if (res <= 150) ans[res][k] = min(ans[res][k], x);
        }
      }
}
signed main() {
  preProcess();
  long long q;
  cin >> q;
  while (q--) {
    long long n, k;
    cin >> n >> k;
    cout << (ans[n][k] == inf ? -1 : ans[n][k]) << endl;
  }
}
