#include <bits/stdc++.h>
using namespace std;
const int M = 2e5;
long long mp[15][M + 5];
void solve() {
  for (int i = 0; i < 10; i++) {
    mp[i][0] = 1;
    for (int j = 1; j < 10 - i; j++) {
      mp[i][j] = 1;
    }
    mp[i][10 - i] = 2;
    for (int j = 10 - i + 1; j < 10; j++) {
      mp[i][j] = mp[i][10 - i];
    }
    for (int j = 10; j <= M; j++) {
      mp[i][j] = ((mp[i][j - 9] % 1000000007) + (mp[i][j - 10] % 1000000007));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  solve();
  int t;
  cin >> t;
  while (t--) {
    string second;
    int m;
    cin >> second >> m;
    long long ans = 0;
    for (auto i : second) {
      ans = ((ans % 1000000007) + (mp[i - '0'][m] % 1000000007));
    }
    cout << ans << '\n';
  }
  return 0;
}
