1. 


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11219 How old are you?
*
* @author Robert Reichart
*
* Status : Accepted
* Runtime: 0.176
*/

import java.io.*;
import java.util.*;

class Main{
public static void main(String... args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(in.readLine());

for (int o = 0; o<cases;o++){
in.readLine();

String line=in.readLine();
String[] strdates1=line.split("/");
line=in.readLine();
String[] strdates2=line.split("/");

int[] intvalues1=new int[3];
int[] intvalues2=new int[3];
for (int i=0;i<3;i++){
intvalues1[i]=Integer.parseInt(strdates1[i]);
intvalues2[i]=Integer.parseInt(strdates2[i]);
}

GregorianCalendar current = new GregorianCalendar();
int cdate = intvalues1[0];
int cmonth = intvalues1[1];
int cyear = intvalues1[2];
int bdate = intvalues2[0];
int bmonth = intvalues2[1];
int byear = intvalues2[2];

int age = cyear - byear;
if (cmonth < bmonth || (cmonth == bmonth && cdate < bdate)){ age = age - 1;}
if (age<0){
System.out.println("Case #" + (o+1) + ": Invalid birth date");
}else if(age>130){
System.out.println("Case #" + (o+1) + ": Check birth date");
}else{
System.out.println("Case #" + (o+1) + ": " + age);
}

}
}
}