S1=""
S2=""
S3=""
L1=[]
L2=[]
a=0
for r_i in range(int(input())):
S1=input()
S2=input()
S3=input()
L1=S2.split("/")
L2=S3.split("/")
for r_j in range(3):
L1[r_j]=int(L1[r_j])
L2[r_j]=int(L2[r_j])
if L1[1]>L2[1]:
a=L1[2]-L2[2]
elif L1[1]==L2[1]:
if L1[0]>=L2[0]:
a=L1[2]-L2[2]
elif L1[0]<L2[0]:
a=L1[2]-L2[2]-1
elif L1[1]<L2[1]:
a=L1[2]-L2[2]-1
if a==abs(a) and a<131:
print("Case #"+str(r_i+1)+":",a)
elif a>130:
print("Case #"+str(r_i+1)+":","Check birth date")
elif a<0:
print("Case #"+str(r_i+1)+":","Invalid birth date")
# I was 56 years old before I die