#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
string check(string a, int k) {
  string res = "";
  while (k--) res += a;
  return res;
}
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int nextPrime(int N) {
  if (N <= 1) return 2;
  int prime = N;
  bool found = false;
  while (!found) {
    prime++;
    if (isPrime(prime)) found = true;
  }
  return prime;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    int m;
    cin >> s >> m;
    long long dp[200005][11];
    memset(dp, 0, sizeof(dp));
    for (long long i = 0; i < 10; i++) dp[0][i] = 1;
    for (long long i = 1; i <= 200003; i++) {
      for (long long j = 0; j < 9; j++) {
        dp[i][j] = dp[i - 1][j + 1];
      }
      dp[i][9] = (dp[i - 1][1] + dp[i - 1][0]) % mod;
      long long ans = 0;
      for (char c : s) ans = (ans + dp[m][c - '0']) % mod;
      cout << ans << '\n';
    }
  }
  return 0;
}
