#include<iostream>
#include<stdio.h>
using namespace std;
#include<string>
int jude_month(string m)
{
if(m=="January") return 1;
if(m=="February") return 2;
if(m=="March") return 3;
if(m=="April") return 4;
if(m=="May") return 5;
if(m=="June") return 6;
if(m=="July") return 7;
if(m=="August") return 8;
if(m=="September") return 9;
if(m=="October") return 10;
if(m=="November") return 11;
if(m=="December") return 12;
}
int main()
{
string month1,month2;
int T;
int day1,year1;
int day2,year2;
int m1,m2;
while(cin>>T)
{
int sum=0;
for(int j=1;j<T+1;j++)
{
cin>>month1;
scanf("%d, %d",&day1, &year1);
cin>>month2;
scanf("%d, %d",&day2, &year2);
cout<<"Case #"<<j<<": ";
m1=jude_month(month1);
m2=jude_month(month2);
for(int i = year1;i<year2+1;i++)
{
if(i%4==0&&i%100!=0 || i%400==0)//是闰年
{
if(i==year1 && year1!=year2)
{
if(m1<2 || m1==2&&day1<=29)
sum=sum+1;
}
if(i>year1 && i<year2)
{
sum=sum+1;
}
if(i==year2&& year1!=year2)
{
if(m2>2 || m2==2&&day2==29)
sum=sum+1;
}
if(year1==year2)
{
if(m1<2&&m2>2 || m1==2&&day1<=29 || m2==2&&day2==29)
sum=sum+1;
}
}
}
cout<<sum<<endl;
sum=0;
}
}
return 0;
}
#include<stdio.h>
using namespace std;
#include<string>
int jude_month(string m)
{
if(m=="January") return 1;
if(m=="February") return 2;
if(m=="March") return 3;
if(m=="April") return 4;
if(m=="May") return 5;
if(m=="June") return 6;
if(m=="July") return 7;
if(m=="August") return 8;
if(m=="September") return 9;
if(m=="October") return 10;
if(m=="November") return 11;
if(m=="December") return 12;
}
int main()
{
string month1,month2;
int T;
int day1,year1;
int day2,year2;
int m1,m2;
while(cin>>T)
{
int sum=0;
for(int j=1;j<T+1;j++)
{
cin>>month1;
scanf("%d, %d",&day1, &year1);
cin>>month2;
scanf("%d, %d",&day2, &year2);
cout<<"Case #"<<j<<": ";
m1=jude_month(month1);
m2=jude_month(month2);
for(int i = year1;i<year2+1;i++)
{
if(i%4==0&&i%100!=0 || i%400==0)//是闰年
{
if(i==year1 && year1!=year2)
{
if(m1<2 || m1==2&&day1<=29)
sum=sum+1;
}
if(i>year1 && i<year2)
{
sum=sum+1;
}
if(i==year2&& year1!=year2)
{
if(m2>2 || m2==2&&day2==29)
sum=sum+1;
}
if(year1==year2)
{
if(m1<2&&m2>2 || m1==2&&day1<=29 || m2==2&&day2==29)
sum=sum+1;
}
}
}
cout<<sum<<endl;
sum=0;
}
}
return 0;
}