#include <bits/stdc++.h>
using namespace std;
const long long vlarge = 1e18 + 7;
int t, n, m, k;
vector<vector<int>> sum;
long long ans;
void precal() {
  sum = vector<vector<int>>(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      sum[i][j] = (2 * i + j) * (j + 1) / 2;
    }
  }
}
void cstru(int st, int len, int cpos) {
  int rem;
  if (cpos > 0) {
    rem = n - sum[st][len] + 9 * (st + len - 9) - 9 * (cpos - 1) * (9 - st + 1);
  } else
    rem = n - sum[st][len];
  if (rem < 0 || rem % (k + 1) != 0) return;
  int fmax = (cpos == 0) ? 9 : 8;
  int dsum = rem / (k + 1);
  long long tans = st;
  long long pow10 = 1;
  for (int i = 1; i <= cpos - 1; i++) {
    pow10 *= 10;
    tans += 9 * pow10;
  }
  int id = 0;
  while (dsum > 0) {
    pow10 *= 10;
    if (id == 0 && st + len > 9) {
      tans += min(dsum, 8) * pow10;
      dsum = max(dsum - 8, 0);
    } else {
      tans += min(dsum, 9) * pow10;
      dsum = max(dsum - 9, 0);
    }
    id = 1;
  }
  ans = min(ans, tans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  precal();
  cin >> t;
  while (t--) {
    ans = vlarge;
    cin >> n >> k;
    for (int i = 0; i < 10 - k; i++) cstru(i, k, 0);
    for (int i = 1; i < 18; i++) {
      for (int j = 10 - k; j < 10; j++) cstru(j, k, i);
    }
    if (ans != vlarge)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
