#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 500;
int arr[maxn];
const int md = 1e9 + 7;
int main() {
  for (int i = 0; i <= 9; i++) {
    arr[i] = 1;
  }
  for (int i = 10; i <= maxn; i++) {
    arr[i] = arr[i - 10] + arr[i - 9];
  }
  long long res = 0;
  int n;
  scanf("%d", &n);
  while (n--) {
    int x, y;
    scanf("%d%d", &x, &y);
    while (x != 0) {
      int a = x % 10;
      x /= 10;
      res += arr[a + y];
    }
    printf("%lld\n", res);
  }
  return 0;
}
