#include <bits/stdc++.h>
using namespace std;
long long n, m, f[2][200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  f[0][0] = f[1][0] = 1;
  for (long i = 1; i <= 200000; i++) {
    f[0][i] = 1;
    if (i >= 10) f[0][i] = f[1][i - 10] + f[0][i - 10];
    f[1][i] = 1;
    if (i >= 9) f[1][i] = f[1][i - 9] + f[0][i - 9];
  }
  long test;
  cin >> test;
  while (test--) {
    cin >> n >> m;
    long long kq = 0;
    while (n > 0) {
      long cs = n % 10;
      if (m >= 10 - cs)
        kq += f[0][m - (10 - cs)] + f[1][m - (10 - cs)];
      else
        kq++;
      n /= 10;
    }
    cout << kq << '\n';
  }
  return 0;
}
