#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LMAX = 1e18;
const long long MAX = 2e5 + 5;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
vector<long long> ans(MAX);
void precalculate() {
  vector<long long> v(10, 0);
  v[9] = 1;
  for (long long i = 1; i < MAX; i++) {
    long long temp1 = v[8];
    for (long long j = 8; j > 1; j--) {
      v[j] = v[j - 1];
    }
    v[1] = (v[9] + v[0]) % MOD;
    v[0] = v[9];
    v[9] = temp1;
    long long temp = 0;
    for (long long j = 0; j <= 9; j++) {
      temp = temp + v[j];
    }
    ans[i] = temp % MOD;
  }
}
int main() {
  ios_base::sync_with_stdio();
  cin.tie();
  cout.tie();
  precalculate();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long digit = 0;
    while (n > 0) {
      long long num = n % 10;
      if ((9 - num) <= m) {
        digit = digit + ans[m - (9 - num)];
      } else {
        digit++;
      }
      n = n / 10;
    }
    cout << digit << "\n";
  }
  return 0;
}
