#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
int br[10][1000];
int prc[700050];
int main() {
  int t;
  cin >> t;
  for (int i = 2; i < 10; i++) {
    for (int j = 0; j < 151; j++) br[i][j] = -1;
  }
  for (int i = 0; i < 700050; i++) {
    int x = i;
    while (x > 0) {
      prc[i] += x % 10;
      x /= 10;
    }
  }
  for (int i = 700000; i >= 0; i--) {
    int tot = 0;
    for (int j = 0; j < 10; j++) {
      tot += prc[i + j];
      br[j][tot] = i;
    }
  }
  for (; t--;) {
    int n, k;
    cin >> n >> k;
    if (k == 0) {
      string ans;
      while (n > 9) {
        ans.push_back('9');
        n -= 9;
      }
      if (n || ans.empty()) ans.push_back(48 + n);
      reverse(ans.begin(), ans.end());
      cout << ans << '\n';
    } else if (k == 1) {
      if (n & 1) {
        string ans;
        int n2 = n / 2;
        if (n2 >= 8) {
          ans.push_back('8');
          n2 -= 8;
        }
        while (n2 > 9) {
          ans.push_back('9');
          n2 -= 9;
        }
        if (n2 || ans.empty()) ans.push_back(n2 + 48);
        reverse(ans.begin(), ans.end());
        cout << ans << '\n';
      } else {
        string ans;
        if (n < 9) {
          cout << "-1\n";
          continue;
        }
        n -= 9;
        ans.push_back('9');
        int n2 = n / 2;
        if (n2 >= 8) {
          ans.push_back('8');
          n2 -= 8;
        }
        while (n2 > 9) {
          ans.push_back('9');
          n2 -= 9;
        }
        if (n2 || ans.empty()) ans.push_back(n2 + 48);
        reverse(ans.begin(), ans.end());
        cout << ans << '\n';
      }
    } else {
      cout << br[k][n] << '\n';
    }
  }
  return 0;
}
