#include <bits/stdc++.h>
using namespace std;
const int X = 999999;
int aa[X + 1];
void init() {
  aa[0] = 0;
  for (int x = 1; x <= X; x++) aa[x] = aa[x / 10] + x % 10;
}
void print(int n) {
  if (n % 9) cout << n % 9;
  n /= 9;
  while (n--) cout << 9;
}
int main() {
  init();
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    if (k == 0)
      print(n);
    else if (k == 1)
      if (n % 2) {
        n = (n - 1) / 2;
        int d = min(n, 8);
        print(n - d);
        cout << d;
      } else if (n < 10)
        cout << -1;
      else {
        n = (n - 10) / 2;
        int d = min(n, 8);
        print(n - d);
        cout << d * 10 + 9;
      }
    else {
      int sum = 0, x = -1;
      for (int y = 0; y <= X; y++) {
        sum += aa[y];
        if (y >= k) {
          if (sum == n) {
            x = y - k;
            break;
          }
          sum -= aa[y - k];
        }
      }
      cout << x;
    }
    cout << '\n';
  }
  return 0;
}
