1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostream> 6 #include <algorithm> 7 #include <climits> 8 #include <queue> 9 #define ll long long 10 11 using namespace std; 12 const int N = 1e4+1000; 13 14 int digit[25],l,k; 15 ll dp[25][100][100]; 16 17 void init() 18 { 19 memset(dp,-1,sizeof(dp)); 20 } 21 22 ll dfs( int cur, int n, int sum, int f) 23 { 24 if(cur == -1) 25 { 26 return (n == 0 && sum == 0) ?1:0; 27 } 28 29 if(!f && dp[cur][n][sum] != -1) 30 return dp[cur][n][sum]; 31 32 ll ans = 0; 33 int len = f?digit[cur]:9; 34 for(int i = 0; i <= len; i++) 35 { 36 ans += dfs(cur-1, (n*10 + i)%k, (sum+i)%k, f&(i == len)); 37 } 38 if(!f) 39 return dp[cur][n][sum] = ans; 40 else 41 return ans; 42 } 43 44 ll work(int num,int mod) 45 { 46 l = 0; 47 while(num > 0) 48 { 49 digit[l++] = num%10; 50 num /= 10; 51 } 52 ll ans = dfs(l-1, 0, 0, 1); 53 return ans; 54 } 55 56 void solve() 57 { 58 int a,b; 59 60 init(); 61 scanf("%d %d %d",&a,&b,&k); 62 if(k > 90) 63 { 64 printf("0\n"); 65 return ; 66 } 67 printf("%lld\n", work(b,k) - work(a-1,k)); 68 69 } 70 71 int main(void) 72 { 73 74 int t,cnt = 0; 75 scanf("%d",&t); 76 while(t--) 77 { 78 printf("Case %d: ",++cnt); 79 solve(); 80 } 81 return 0; 82 }