#include <bits/stdc++.h>
using namespace std;
int _r() {
  int x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
const long long MOD = 1e9 + 7;
long long q_pow(int x, int y) {
  long long base = x;
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans *= base;
      ans %= MOD;
    }
    y >>= 1;
    base *= base;
    base %= MOD;
  }
  return ans;
}
long long C(long long n, long long m) {
  long long sum = 1;
  for (int i = 0; i < m; i++) {
    sum *= n - i;
    sum /= (long long)i + 1;
    sum %= MOD;
  }
  return sum;
}
int main() {
  int t = _r(), cnt = 0;
  long long n, ans = 0, k, q;
  while (t--) {
    n = _r(), k = _r();
    ans = 0;
    while (n) {
      long long x = n % 10, last = k;
      ans++;
      n /= 10;
      last -= 10 - x;
      q = last / 9;
      if (last > 0) {
        ans++;
        ans += q_pow(2, q) - 2;
        ans %= MOD;
        last -= q * 9;
        for (int i = 0; i <= last; i++) {
          ans += C(q, i);
          ans %= MOD;
        }
      } else if (last == 0)
        ans++;
    }
    printf("%lld\n", ans % MOD);
  }
  return 0;
}
