#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
using namespace std;
long long ESP = 1e18;
bool isPrime[1000000];
void sieve(long long int N) {
  for (long long i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (int j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
}
bool anagram(char *s1, char *s2) {
  long long count[256];
  memset(count, 0, sizeof(count));
  long long i;
  for (i = 0; s1[i] && s2[i]; i++) {
    count[s1[i]]++;
    count[s2[i]]--;
  }
  if (s1[i] || s2[i]) {
    return false;
  }
  for (int(i) = 0; i < 256; ++i) {
    if (count[i]) {
      return false;
    }
  }
  return true;
}
int find_largest_digit(int n) {
  int mx = 0;
  while (n > 0) {
    mx = max(mx, n % 10);
    n /= 10;
  }
  return mx;
}
long long no_of_digits(long long n) {
  long long ans = 0;
  while (n > 0) {
    ans++;
    n /= 10;
  }
  return ans;
}
long long moduloMultiplication(long long a, long long b, long long zz) {
  long long res = 0;
  a %= zz;
  while (b) {
    if (b & 1) res = (res + a) % zz;
    a = (2 * a) % zz;
    b >>= 1;
  }
  return res;
}
long long to_int(string s) {
  bool o = true;
  long long ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    ans = ans * 10 + (s[i] - 48);
  }
  return ans;
}
inline long long powmod(long long x, long long n, long long m) {
  if (n == 0 || x == 1)
    return 1;
  else if (n % 2 == 0) {
    return powmod((x * x) % m, n / 2, m);
  } else {
    return x * (powmod((x * x) % m, (n - 1) / 2, m)) % m;
  }
}
long long poww(long long a, long long b) {
  if (b == 0 || a == 1) return 1;
  long long half = poww(a, (b / 2));
  if (half < 0 || half > ESP) return -1;
  long long full = (half * half);
  if (half != 0 && full / half != half) {
    return -1;
  }
  if (b % 2) {
    if (full * a < 0 || full * a > ESP) return -1;
  }
  if (full < 0 || full > ESP) return -1;
  if (b % 2) {
    long long x = a * full;
    if (a != 0 && x / a != full) {
      return -1;
    }
    return (x);
  }
  return full;
}
long long invmod(long long a, long long modulo) {
  long long check = powmod(a, modulo - 2, modulo) % modulo;
  return check;
}
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long min(long long a, int b) {
  if (a < b) return a;
  return b;
}
long long min(int a, long long b) {
  if (a < b) return a;
  return b;
}
long long max(long long a, int b) {
  if (a > b) return a;
  return b;
}
long long max(int a, long long b) {
  if (a > b) return a;
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void yes() {
  cout << "YES"
       << "\n";
}
void no() {
  cout << "NO"
       << "\n";
}
vector<int> factorize(int n) {
  vector<int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res.push_back(i);
      n /= i;
    }
  }
  if (n != 1) {
    res.push_back(n);
  }
  return res;
}
void printDivisors(int n) {
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        printf("%d ", i);
      else
        printf("%d %d ", i, n / i);
    }
  }
}
int phi(int n) {
  int result = n;
  for (int p = 2; p * p <= n; ++p) {
    if (n % p == 0) {
      while (n % p == 0) n /= p;
      result -= result / p;
    }
  }
  if (n > 1) result -= result / n;
  return result;
}
bool presents(vector<long long> v, int x) {
  bool flag = false;
  for (decltype(v.begin()) it = v.begin(); it != v.end(); it++) {
    if (*it == x) flag = true;
  }
  return flag;
}
long long ncr(long long n, long long r) {
  if (n < r) return 0;
  long long p = 1, k = 1;
  if (n - r < r) r = n - r;
  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = gcd(p, k);
      p /= m;
      k /= m;
      n--;
      r--;
    }
  } else
    p = 1;
  return p;
}
int tc(char c) {
  int k = c - 97;
  return k;
}
void okms() { return; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << showpoint;
  cout.precision(15);
  long long test;
  cin >> test;
  long long dp[200100];
  memset(dp, 0, sizeof(dp));
  for (int(i) = 0; i < 9; ++i) dp[i] = 2;
  dp[9] = 3;
  for (int(i) = 10; i < 200100; ++i)
    dp[i] = ((dp[i - 9]) % 1000000007 + (dp[i - 10]) % 1000000007) % 1000000007;
  while (test--) {
    string n;
    long long m;
    cin >> n >> m;
    long long ans{};
    for (auto c : n) {
      long long k = c - '0' + m - 10;
      if (k < 0)
        ans += 1;
      else
        ans += dp[k] %= 1000000007;
    }
    cout << ans << "\n";
  }
  return 0;
}
