#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  cin >> T;
  long long d0[200020] = {0}, d1[200020] = {0};
  for (long long i = 0; i <= 9; i++) d0[i] = 1;
  for (long long i = 0; i <= 8; i++) d1[i] = 1;
  d1[9] = 2;
  for (long long i = 10; i <= 200019; i++) {
    d0[i] = d0[i - 10] + d1[i - 10];
    d1[i] = d0[i - 9] + d1[i - 9];
  }
  while (T--) {
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    while (n) {
      long long dig = n % 10;
      n /= 10;
      ans += d0[m + dig];
    }
    cout << ans << endl;
  }
}
