#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long expo(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return res;
}
void extendgcd(long long a, long long b, long long *v) {
  if (b == 0) {
    v[0] = 1;
    v[1] = 0;
    v[2] = a;
    return;
  }
  extendgcd(b, a % b, v);
  long long x = v[1];
  v[1] = v[0] - v[1] * (a / b);
  v[0] = x;
  return;
}
long long mminv(long long a, long long b) {
  long long arr[3];
  extendgcd(a, b, arr);
  return arr[0];
}
long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }
bool revsort(long long a, long long b) { return a > b; }
void swap(int &x, int &y) {
  int temp = x;
  x = y;
  y = temp;
}
long long combination(long long n, long long r, long long m, long long *fact,
                      long long *ifact) {
  long long val1 = fact[n];
  long long val2 = ifact[n - r];
  long long val3 = ifact[r];
  return (((val1 * val2) % m) * val3) % m;
}
vector<long long> sieve(int n) {
  int *arr = new int[n + 1]();
  vector<long long> vect;
  for (int i = 2; i <= n; i++)
    if (arr[i] == 0) {
      vect.push_back(i);
      for (int j = 2 * i; j <= n; j += i) arr[j] = 1;
    }
  return vect;
}
long long mod_add(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (((a - b) % m) + m) % m;
}
long long mod_div(long long a, long long b, long long m) {
  a = a % m;
  b = b % m;
  return (mod_mul(a, mminvprime(b, m), m) + m) % m;
}
const int M = 2e5 + 8;
long long dp[M][10];
void solve() {
  string n;
  int m;
  cin >> n >> m;
  vector<long long> v(10, 0);
  for (int i = 0; i <= 9; i++) {
    int c = (n[i] - '0');
    v[c] += 1;
  }
  vector<int> preComp(10, 0);
  for (int i = 0; i <= 9; i++) {
    preComp[i] = dp[m][i];
  }
  long long ans = 0;
  for (int i = 0; i < 10; i++) {
    int c = i;
    vector<int> cop = preComp;
    long long preAns = 0;
    while (c--) {
      long long prev = cop[0];
      for (int j = 1; j <= 9; j++) {
        long long temp = cop[j];
        cop[j] = prev;
        prev = temp;
      }
      cop[0] = prev;
      cop[1] = mod_add(cop[1], prev, 1000000007);
    }
    for (int k = 0; k <= 9; k++) {
      preAns = mod_add(preAns, cop[k], 1000000007);
    }
    ans = mod_add(ans, mod_mul(v[i], preAns, 1000000007), 1000000007);
  }
  cout << ans << "\n";
}
int main() {
  for (int i = 0; i <= 9; i++) {
    dp[0][i] = 0LL;
  }
  dp[0][0] = 1;
  for (int i = 1; i < M; i++) {
    for (int j = 1; j <= 9; j++) {
      dp[i][j] = dp[i - 1][j - 1];
    }
    dp[i][0] = dp[i - 1][9];
    dp[i][1] = mod_add(dp[i][1], dp[i - 1][9], 1000000007);
  }
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
