#include <bits/stdc++.h>
using namespace std;
long long get_smallest(int remaining, int carry_from, int k) {
  bool was_carry = ((k + 1 - carry_from) != 0);
  remaining -= (k + 1 - carry_from);
  if (remaining == 0) return 0;
  if (remaining < 0) return -1;
  long long new_result = -1;
  if (remaining % (k + 1) == 0) {
    int first_digit = (remaining / (k + 1)) % 9;
    int nines = (remaining / (k + 1)) / 9;
    if (was_carry) first_digit += 1;
    new_result = first_digit;
    while (nines != 0) {
      new_result = new_result * 10 + 9;
      nines--;
    }
    if (was_carry) new_result -= 1;
  }
  if (was_carry) remaining += (k + 1 - carry_from);
  remaining -= carry_from * 9;
  if (remaining < 0) return new_result;
  long long new_new_result = get_smallest(remaining, carry_from, k);
  if (new_new_result == -1) {
    return new_result;
  } else {
    new_new_result = new_new_result * 10 + 9;
    return min(new_result, new_new_result);
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  long long result = -1;
  for (int starting_digit = 0; starting_digit < 10; starting_digit++) {
    int units = 0;
    bool carry = false;
    int carry_start = k + 1;
    for (int i = 0; i <= k; i++) {
      units += (starting_digit + i) % 10;
      if (starting_digit + i >= 10 && (!carry)) {
        carry = true;
        carry_start = i;
      }
    }
    if (units > n)
      continue;
    else if (units == n && !carry) {
      if (result == -1 || starting_digit < result) {
        result = starting_digit;
      }
    } else {
      long long new_result = get_smallest(n - units, carry_start, k);
      if (new_result != -1) {
        new_result = new_result * 10 + starting_digit;
      }
      if (result == -1 || (new_result != -1 && new_result < result)) {
        result = new_result;
      }
    }
  }
  cout << result << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
}
