#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 12;
long long a[N];
void solve() {
  string s;
  long long m;
  cin >> s >> m;
  long long ans = 0;
  for (long long i = 0; i < s.size(); i++) {
    ans = (ans + a[s[i] - '0' + m]) % 1000000007;
  }
  cout << ans << '\n';
}
signed main() {
  std ::ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (long long i = 0; i < 9; i++) {
    a[i] = 1;
  }
  a[9] = 2;
  for (long long i = 10; i < N; i++) {
    a[i] = (a[i - 9] + a[i - 10]) % 1000000007;
  }
  long long tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
