#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  long long int dp[200005][11];
  for (int i = 0; i < 10; i++) dp[0][i] = 1;
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < 9; j++) dp[i][j] = dp[i - 1][j + 1];
    dp[i][9] = dp[i - 1][0] + dp[i - 1][1];
    for (int j = 0; j <= 9; j++) dp[i][j] %= 1000000007;
  }
  while (t--) {
    string s;
    int x;
    cin >> s >> x;
    long long ans = 0;
    for (char ch : s) ans = (ans + dp[ch - '0'][x]) % 1000000007;
    cout << ans << endl;
  }
}
