#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long int mul[(int)2e4 + 5], pre[(int)2e5 + 20] = {};
void f() {
  mul[0] = 1;
  for (int i = 1; i < 2e4 + 6; i++) {
    mul[i] = mul[i - 1] * i;
    mul[i] %= MOD;
  }
}
long long int mypow(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long int c = mypow(a, b / 2);
  (c *= c) %= MOD;
  if (b & 1) (c *= a) %= MOD;
  return c;
}
long long int c(long long int a, long long int b) {
  if (a < b || b < 0)
    return 0;
  else if (a == 0 && b == 0)
    return 1;
  else if (a == 0)
    return 0;
  else
    return ((mul[a] * mypow(mul[a - b], MOD - 2)) % MOD) *
           mypow(mul[b], MOD - 2) % MOD;
}
long long int solve(long long int a) {
  long long int x = (a / 10) + (a % 10 != 0), ans = 0;
  ans = mypow(2, x);
  long long int j = 0;
  for (long long int i = 10 * x; i > a; i--) {
    ans -= c(x - 1, j);
    while (ans < 0) ans += MOD;
    ans %= MOD;
    j++;
    if (j > x - 1) break;
  }
  pre[a] = ans;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  f();
  int t;
  cin >> t;
  while (t--) {
    long long int m;
    string n;
    cin >> n >> m;
    int temp = n.size();
    long long int ans = 0;
    for (int i = 0; i < temp; i++) {
      if (pre[m + n[i] - '0'])
        ans += pre[m + n[i] - '0'];
      else
        ans += solve(m + n[i] - '0');
      ans %= MOD;
    }
    while (ans < 0) ans += MOD;
    cout << ans << '\n';
  }
}
