#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
const long long M = 1e9 + 7;
const int N = 1e6 + 7;
long long dp[10][10][200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  for (long long i = 0; i < (int)1; i++) {
    for (long long j = 0; j < (int)10; j++) {
      long long cnt[10] = {0};
      cnt[i] = j;
      for (long long k = 0; k < (int)200005; k++) {
        long long x = cnt[9];
        cnt[9] = 0;
        for (long long l = 8; l >= 0; l--) {
          cnt[l + 1] = (cnt[l + 1] + cnt[l]) % M;
          cnt[l] = 0;
        }
        cnt[0] = (cnt[0] + x) % M, cnt[1] = (cnt[1] + x) % M;
        long long sum = 0;
        for (long long l = 0; l < (int)10; l++) sum = (sum + cnt[l]) % M;
        dp[i][j][k + 1] = sum;
      }
    }
  }
  int tt;
  cin >> tt;
  while (tt--) {
    long long n, m;
    cin >> n >> m;
    long long cnt[10] = {0};
    while (n) {
      cnt[n % 10]++;
      n /= 10;
    }
    long long sum = 0;
    for (long long i = 0; i < (int)10; i++) {
      for (long long j = 0; j < (int)10; j++) dp[i][j][0] = j;
    }
    for (long long i = 1; i < (int)10; i++) {
      for (long long j = 0; j < (int)10; j++) {
        dp[i][j][m] = dp[0][j][m + i];
      }
    }
    for (long long i = 0; i < (int)10; i++) {
      sum = (sum + dp[i][cnt[i]][m]) % M;
    }
    cout << sum << "\n";
  }
  return 0;
}
