#include <bits/stdc++.h>
using namespace std;
long long dp[200009];
void solve() {
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  while (n > 0) {
    long long num = n % 10;
    n /= 10;
    ans += (m + num < 10) ? 1 : dp[num - 10 + m];
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  for (int i = 0; i < 200009; i++) {
    if (i < 9)
      dp[i] = 2;
    else if (i == 9)
      dp[i] = 3;
    else
      dp[i] = dp[i - 9] + dp[i - 10];
  }
  while (t--) {
    solve();
  }
}
