#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const int mod = 1e9 + 7;
inline long long read() {
  long long f = 1;
  long long x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * f;
}
long long a[11], b[11], c[200], ans[maxn + 50];
void init() {
  a[0] = 1;
  ans[0] = 1;
  for (int j = 1; j <= maxn; j++) {
    long long t = a[9] % mod;
    for (int i = 9; i >= 1; i--) {
      a[i] = a[i - 1] % mod;
    }
    a[0] = t;
    a[1] = (a[1] + t) % mod;
    ans[j] = (ans[j - 1] + a[9]) % mod;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  init();
  long long t;
  cin >> t;
  while (t--) {
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    string s;
    cin >> s;
    for (int i = 0; i <= s.length() - 1; i++) {
      b[i] = s[i] - '0';
    }
    int op;
    cin >> op;
    c[0] = ans[op - 1];
    for (int i = 1; i <= 9; i++) {
      c[i] = ans[op - 1 + i] % mod;
    }
    long long sum = 0;
    for (int i = 0; i <= s.length() - 1; i++) {
      sum = c[b[i]];
    }
    cout << sum % mod << endl;
  }
  return 0;
}
