#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
int sum[105][15];
long long solve(int x) {
  long long ans = x % 9;
  x -= ans;
  while (x) {
    ans = ans * 10 + 9;
    x -= 9;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < 100; i++) {
    sum[i][0] = i % 10 + i / 10;
    for (int j = 1; j < 10; j++) {
      sum[i][j] = sum[i][j - 1] + (i + j) % 10 + (i + j) / 10;
    }
  }
  while (T--) {
    int n, k;
    cin >> n >> k;
    if (n < k * (k + 1) / 2) {
      cout << "-1\n";
      continue;
    }
    long long ans = 1e18;
    for (int i = 0; i < 100 - k; i++) {
      int x = n - sum[i][k];
      if (x % (k + 1) || x < 0) continue;
      ans = min(ans, solve(x / (k + 1)) * 100 + i);
    }
    if (ans == 1e18)
      cout << "-1\n";
    else
      cout << ans << endl;
  }
}
