#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
void inputoutput();
void timelap();
int dp[200005][10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  for (int i = 0; i <= 9; ++i) dp[0][i] = 1;
  for (int i = 1; i <= 200001; ++i) {
    for (int j = 0; j <= 9; ++j) {
      if (j < 9)
        dp[i][j] += dp[i - 1][j + 1];
      else
        dp[i][j] += dp[i - 1][0] + dp[i - 1][1];
    }
  }
  int t;
  cin >> t;
  while (t--) {
    string number;
    cin >> number;
    int m;
    cin >> m;
    int res = 0;
    for (int i = 0; i < number.length(); i++) {
      res = res % 1000000007 + dp[m][number[i] - '0'] % 1000000007;
    }
    cout << res << '\n';
  }
  return 0;
}
void timelap() {}
