#include<iostream>
//#include<string.h>
//#include<stdbool.h>
using namespace std;
int main()
{
string c,s;
string month[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"};
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
int d,y,d2,y2,m=-1,m2=-1;
char ch;
cin>>c;
scanf("%d, %d",&d,&y);
cin>>s;
scanf("%d, %d",&d2,&y2);
for(int j=0;j<12;j++)
{
if(month[j]==c)m=j+1;
if(month[j]==s)m2=j+1;
if(m!=-1&&m2!=-1) break;
}
y+=(m>2);
y2-=(m2>2);
if(y>y2) y2=y;
int num=0;
if(y%4!=0) y=(y/4+1)*(4);
if(y>y2) {printf("0\n");continue;
}
for(int j=y;j<=y2;j+=4)
{
if(j%4==0)
{
if(j%100!=0||j%400==0)
num++;
}
}
printf("Case %d: %d\n",i,num);
}
return 0;
}