#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 1000000007;
const long long INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<pair<int, int>> T;
  int sum = 0, length = 2;
  vector<long long> K(10, 0);
  K[1] = 1;
  K[0] = 1;
  T.push_back(make_pair(sum, length));
  while (sum < 100010) {
    int j = 9;
    while (!K[j]) {
      j--;
    }
    int num = 10 - j;
    sum += (10 - j);
    length += K[j];
    length %= M;
    T.push_back(make_pair(sum, length));
    vector<long long> Temp(10, 0);
    Temp[1] = K[j];
    Temp[0] = K[j];
    while (--j >= 0) {
      Temp[j + num] += K[j];
    }
    K = Temp;
  }
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<int> C(10, 0);
    while (n > 0) {
      C[n % 10]++;
      n /= 10;
    }
    int l = 0, h = T.size() - 1, index = 0;
    while (l <= h) {
      int mid = l + (h - l) / 2;
      if (T[mid].first <= m) {
        index = mid;
        l = mid + 1;
      } else {
        h = mid - 1;
      }
    }
    long long ans = 0;
    for (int i = 0; i < 10; i++) {
      long long num = m - (10 - i);
      if (num >= 0) {
        long long k = index;
        while (T[k].first > num) {
          k--;
        }
        ans += ((C[i] * T[k].second) % M);
      } else
        ans += C[i];
      ans %= M;
    }
    cout << ans << endl;
  }
  return 0;
}
