#include <bits/stdc++.h>
using namespace std;
string ans = "99999999999999999999999";
bool ism(string S) {
  if (S.size() > 1 && S[0] == '0') S.erase(0, 1);
  if (S.size() < ans.size()) return true;
  if (S.size() > ans.size()) return false;
  for (int x = 0; x < ans.size(); x++) {
    if (S[x] > ans[x])
      return false;
    else if (S[x] < ans[x])
      return true;
    else
      continue;
  }
  return true;
}
void calc(int k, int sum, string ps, int tbl) {
  if (sum < 0) return;
  if (sum == 0 && tbl != -1) return;
  if (tbl == -1 || sum == 0) {
    if (sum % k) return;
    sum /= k;
    string tmp = "";
    while (sum) {
      tmp += to_string(min(sum, 9));
      sum -= min(sum, 9);
    }
    reverse(tmp.begin(), tmp.end());
    if (ism(tmp + ps)) ans = tmp + ps;
    if (ans.size() > 1 && ans[0] == '0') ans.erase(0, 1);
    return;
  }
  for (int x = 0; x < 9; x++) {
    int vsum = sum;
    vsum -= x * (tbl - 1);
    vsum -= (x + 1) * (k - tbl + 1);
    calc(k, vsum, to_string(x) + ps, -1);
  }
  if (true) {
    int vsum = sum;
    vsum -= 9 * (tbl - 1);
    calc(k, vsum, to_string(9) + ps, tbl);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    k++;
    vector<int> jjj = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    for (int f = 0; f < 10; f++) {
      int vsum = n;
      for (int p = 0; p < k; p++) vsum -= jjj[(f + p) % 10];
      if (f + k < 11)
        calc(k, vsum, to_string(f), -1);
      else
        calc(k, vsum, to_string(f), 11 - f);
    }
    if (ans == "99999999999999999999999")
      cout << -1 << endl;
    else
      cout << ans << endl;
    ans = "99999999999999999999999";
  }
  return 0;
}
