#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int f = 1, x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int main() {
  int t = read();
  while (t--) {
    int n = read();
    int k = read();
    long long ans = -1;
    for (int c = 0; c < 10; c++) {
      for (int d = 0; 9 * d + c <= n; ++d) {
        int a = k + 1;
        int b = 0;
        for (int i = 0; i <= k; i++)
          b += (i + c) % 10 + (i + c < 10 ? 9 * d : 1);
        b = n - b;
        if (b < 0 || b % a != 0) continue;
        int x = b / a;
        long long v;
        if (x < 8)
          v = x;
        else {
          x -= 8;
          v = x % 9;
          x -= v;
          for (int i = 0; i < x / 9; i++) v = 10 * v + 9;
          v = 10 * v + 8;
        }
        for (int i = 0; i < d; i++) v = v * 10 + 9;
        v = 10 * v + c;
        if (v < 1e18 && (ans == -1 || v < ans)) ans = v;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
