#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long sc(long long x) {
  long long suma = 0;
  while (x > 0) suma += x % 10, x /= 10;
  return suma;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long test;
  cin >> test;
  vector<long long> mini(10, -1);
  vector<vector<long long> > mat(10000, mini);
  for (int i = 2; i <= 9; i++) {
    long long s = 0, f = i;
    long long suma = 0;
    for (int j = s; j <= f; j++) suma += sc(j);
    mat[suma][i] = s;
    while (f <= 1000000) {
      suma -= sc(s), s++;
      f++, suma += sc(f);
      if (mat[suma][i] == -1) mat[suma][i] = s;
    }
  }
  for (int i = 1; i <= 150; i++) {
    long long djel = i / 9;
    long long t = 0;
    if (i % 9 != 0) t = (i % 9);
    for (int j = 0; j < djel; j++) t *= 10, t += 9;
    mat[i][0] = t;
  }
  for (int i = 1; i <= 150; i++) {
    if (i <= 17 && i % 2 == 1) {
      mat[i][1] = i / 2;
      continue;
    }
    if (i > 17 && i % 2 == 1) {
      long long te = i - 17;
      te /= 2;
      long long djel = te / 9;
      long long t = 0;
      if (te % 9 != 0) t = (te % 9);
      for (int j = 0; j < djel; j++) t *= 10, t += 9;
      t *= 10, t += 8;
      mat[i][1] = t;
    }
    if (i >= 10 && i % 2 == 0) {
      long long te = i - 9;
      te /= 2;
      long long djel = te / 9;
      long long t = 0;
      if (te > 8) t += 1;
      if (te % 9 != 0) t += (te % 9);
      for (int j = 0; j < djel; j++) t *= 10, t += 9;
      if (te > 8) t--;
      t *= 10, t += 9;
      mat[i][1] = t;
    }
  }
  while (test--) {
    long long n, k;
    cin >> n >> k;
    cout << mat[n][k] << endl;
  }
}
