#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    string ans = "";
    for (int i = 0; i <= 16; i++) {
      for (int j = 0; j <= 9; j++) {
        int n1;
        int a = min(10 - j, k + 1);
        n1 = n - i * 9 * a - (k + 1 - a);
        for (int x = 0; x <= k; x++) {
          n1 -= (x + j) % 10;
        }
        if (n1 >= 0 && n1 % (k + 1) == 0) {
          string temp = "";
          n1 /= k + 1;
          if (n1 >= 8) {
            if ((n1 - 8) % 9 != 0) temp += ('0' + (n1 - 8) % 9);
            n1 -= (n1 - 8) % 9;
            for (int x = 0; x < n1 / 9; x++) temp += "9";
            if (n1 >= 8) temp += "8";
          } else if (n1 > 0) {
            temp += (n1 + '0');
          }
          for (int x = 0; x < i; x++) temp += "9";
          temp += (j + '0');
          if (ans == "")
            ans = temp;
          else if (ans.size() > temp.size() ||
                   (ans.size() == temp.size() && ans > temp)) {
            ans = temp;
          }
        }
      }
    }
    if (ans == "")
      cout << "-1"
           << "\n";
    else
      cout << ans << "\n";
  }
}
