#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9 + 7);
const long long inf = (1000000000000000000);
long long power(long long a, long long b) {
  long long res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % MOD;
      b--;
    }
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, j, k, c, f;
  long long m = 200000;
  vector<vector<long long> > dp(m + 1, vector<long long>(10));
  for (i = 0; i <= 9; i++) dp[0][i] = 1;
  for (i = 1; i <= m; i++) {
    dp[i][9] = dp[i - 1][0] + dp[i - 1][1];
    for (j = 8; j >= 0; j--) dp[i][j] = dp[i - 1][j + 1];
  }
  cin >> t;
  while (t--) {
    long long m;
    cin >> n >> m;
    long long ans = 0;
    while (n) ans += dp[m][n % 10], n /= 10;
    cout << ans << "\n";
  }
  return 0;
}
