#include <bits/stdc++.h>
using namespace std;
long long n, ans, m, s, k;
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> s >> m;
    k = 0;
    for (int j = 0; j < m; j++) {
      for (; s > 0; s /= 10, k *= 10, ans %= 1000000007) {
        if (j == 0) {
          ans++;
        }
        if (s % 10 == 9) {
          k *= 10;
          ans++;
        }
        k += (s % 10) + 1;
      }
      s = k;
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
