#include <bits/stdc++.h>
using namespace std;
const int mxN = 7e5 + 5;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
vector<vector<int> > dp(mxN, vector<int>(10, 1e9));
void solve() {
  int n, k;
  scanf("%d %d", &n, &k);
  if (k == 0) {
    long long ans = 0;
    long long i = 1;
    while (1) {
      if (n > 9) {
        ans += i * 9;
        n -= 9;
      } else {
        ans += i * n;
        break;
      }
      i *= 10LL;
    }
    cout << ans << '\n';
    return;
  }
  if (k == 1 && n >= 40) {
    int temp = n % 9;
    int first_digit = 0;
    if (temp & 1) {
      first_digit = (temp + 1) / 2;
      n -= 2 * first_digit;
    } else {
      first_digit = (temp + 10) / 2;
      n -= 2 * first_digit;
    }
    cout << first_digit;
    int rem = n % 18;
    if (rem == 17) {
      int cnt = n / 18;
      while (cnt--) {
        cout << 9;
      }
      cout << 8;
    } else if (rem == 8) {
      int cnt = n / 18 - 1;
      while (cnt--) {
        cout << 9;
      }
      cout << 89;
    }
    cout << '\n';
    return;
  }
  if (dp[n][k] == 1e9)
    cout << -1 << '\n';
  else
    cout << dp[n][k] << '\n';
  return;
}
int main() {
  int t = 1;
  cin >> t;
  for (int i = 0; i < mxN; i++) {
    int sum = 0;
    for (int j = 0; j <= 9; j++) {
      int temp = i + j;
      int cnt = 0;
      while (temp > 0) {
        cnt += temp % 10;
        temp /= 10;
      }
      sum += cnt;
      dp[sum][j] = min(dp[sum][j], i);
    }
  }
  while (t--) {
    solve();
  }
}
