#include <bits/stdc++.h>
using namespace std;
long long find_set(long long v, vector<long long> &p) {
  if (v == p[v]) return v;
  return p[v] = find_set(p[v], p);
}
void union_set(long long a, long long b, vector<long long> &p) {
  a = find_set(a, p);
  b = find_set(b, p);
  if (a != b) {
    p[b] = a;
  }
}
bool mysort(pair<long long, long long> a, pair<long long, long long> b) {
  return a.first >= b.first;
}
long long n = 2e5 + 1;
vector<vector<long long>> dp(10, vector<long long>(n, 1));
void solve() {
  string s;
  cin >> s;
  long long m;
  cin >> m;
  long long n = s.size();
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += (dp[s[i] - '0'][m]);
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  for (long long i = 0; i < 9; i++) {
    dp[i][0] = 1;
    dp[i][1] = 1;
  }
  dp[9][0] = 1;
  dp[9][1] = 2;
  for (long long j = 2; j < n; j++) {
    for (long long i = 0; i < 9; i++) {
      dp[i][j] = dp[i + 1][j - 1];
    }
    dp[9][j] = dp[1][j - 1] + dp[0][j - 1];
  }
  while (t--) solve();
  return 0;
}
