#include <bits/stdc++.h>
using namespace std;
void fast_IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
const int INF = 1e9;
const int DEBUG = 1;
const int MAXN = 1e6;
vector<vector<int>> dp;
int sum(int x) {
  int res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
void preinit() {
  dp.resize(151);
  for (int i = 0; i <= 150; ++i) {
    dp[i].resize(10, INF);
  }
  for (int x = 0; x < MAXN; ++x) {
    int res = 0;
    for (int j = 0; j < 10; ++j) {
      res += sum(x + j);
      if (res <= 150) {
        dp[res][j] = min(x, dp[res][j]);
      }
    }
  }
}
int n, k;
void init() { cin >> n >> k; }
signed main() {
  preinit();
  int q = 1;
  cin >> q;
  for (int qq = 0; qq < q; ++qq) {
    init();
    if (k == 0) {
      vector<int> ans;
      while (n > 0) {
        if (n > 9) {
          ans.push_back(9);
          n -= 9;
        } else {
          ans.push_back(n);
          n = 0;
        }
      }
      reverse(ans.begin(), ans.end());
      for (int elem : ans) {
        cout << elem;
      }
      cout << endl;
    } else if (k == 1 && n > 45) {
      if (n % 2 == 1) {
        int n2 = (n - 1) / 2;
        if (n2 % 9 == 0) {
          int chst = n2 / 9;
          cout << 1;
          for (int i = 0; i < chst - 1; ++i) {
            cout << 9;
          }
          cout << 8;
          cout << endl;
        } else {
          int ost = n2 % 9;
          int chst = n2 / 9;
          cout << ost + 1;
          for (int i = 0; i < chst - 1; ++i) {
            cout << 9;
          }
          cout << 8;
          cout << endl;
        }
      } else {
        int n10 = (n - 10) / 2;
        if (n10 % 9 == 0) {
          cout << 1;
          n10--;
          cout << n10 % 9 + 1;
          for (int i = 0; i < n10 / 9 - 1; ++i) {
            cout << 9;
          }
          cout << 89;
          cout << endl;
        } else {
          cout << n10 % 9 + 1;
          for (int i = 0; i < n10 / 9 - 1; ++i) {
            cout << 9;
          }
          cout << 89;
          cout << endl;
        }
      }
    } else if (dp[n][k] != INF) {
      cout << dp[n][k] << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
