#include <bits/stdc++.h>
using namespace std;
int sm(long long x) {
  int ans = 0;
  while (x > 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
long long int answer[160][10];
void check(long long x) {
  int s = 0;
  for (int k = 0; k <= 9; k++) {
    s += sm(x + k);
    if (s > 150) {
      break;
    }
    if (answer[s][k] == -1 || answer[s][k] > x) {
      answer[s][k] = x;
    }
  }
}
int main() {
  int tests;
  scanf("%d", &tests);
  for (int i = 1; i <= 150; ++i) {
    for (int j = 0; j <= 9; ++j) {
      answer[i][j] = -1;
    }
  }
  for (int x = 0; x < 10000; ++x) {
    check(x);
  }
  for (int a = 1; a < 100; ++a) {
    long long ax = a;
    long long bx = 0;
    for (int b = 0; b <= 13; ++b) {
      for (int c = 0; c < 100; ++c) {
        long long x = ax * 100 + bx * 100 + c;
        check(x);
      }
      ax *= 10;
      bx = bx * 10 + 9;
    }
  }
  for (int test = 0; test < tests; ++test) {
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%lld\n", answer[n][k]);
  }
  return 0;
}
