#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[12], b[12][maxn];
int main() {
  int t, ans, n, m, c, x;
  scanf("%d", &t);
  for (int i = 0; i < 10; i++) {
    memset(a, 0, sizeof(a));
    a[i] = b[i][0] = 1;
    for (int j = 1; j < maxn; j++) {
      for (int k = 10; k > 0; k--) a[k] = a[k - 1];
      a[0] = a[10];
      a[1] = a[1] + a[10];
      b[i][j] = b[i][j - 1] + a[10];
    }
  }
  while (t--) {
    scanf("%d%d", &n, &m);
    ans = 0;
    while (n > 0) {
      x = n % 10;
      n = n / 10;
      ans = ans + b[x][m];
    }
    printf("%d\n", ans);
  }
  return 0;
}
