1.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
* Angewandte Mathematik, SS11
* Problem: 11356 - Dates
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2341
*
* @author Unverzart Michael
* @author Wurth Manuel
* @version 1.0, 22/6/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.136
*/

public class Main {
public static void main(String[] args) throws Exception{

TreeMap<Integer,String> map = new TreeMap<Integer,String>();
map.put(1,"January");
map.put(2,"February");
map.put(3,"March");
map.put(4,"April");
map.put(5,"May");
map.put(6,"June");
map.put(7,"July");
map.put(8,"August");
map.put(9,"September");
map.put(10,"October");
map.put(11,"November");
map.put(12,"December");

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int t = new Integer(reader.readLine());
for(int i = 1; i<=t; i++){
StringTokenizer st = new StringTokenizer(reader.readLine(),"-");
int year = new Integer(st.nextToken());
String input = st.nextToken();
int month = 0;
for(Entry<Integer, String> tmp : map.entrySet()) {
if(tmp.getValue().equals(input)) {
month=tmp.getKey();
break;
}
}
int day = new Integer(st.nextToken());
int plus = new Integer(reader.readLine());
do {
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (plus>(31-day))
{
plus=(day+plus)-31;
day=0;
month++;
}
else
{
day=day+plus;
plus=0;
}
break;
case 4:
case 6:
case 9:
case 11:
if (plus>(30-day))
{
plus=(day+plus)-30;
day=0;
month++;
}
else
{
day=day+plus;
plus=0;
}
break;
case 2:
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
{
if (plus>(29-day))
{
plus=(day+plus)-29;
day=0;
month++;
}
else
{
day=day+plus;
plus=0;
}
}
else
{
if (plus>(28-day))
{
plus=(day+plus)-28;
day=0;
month++;
}
else
{
day=day+plus;
plus=0;
}
}
break;
default:
year++;
month=1;
break;
}
} while (plus>0);

System.out.format("Case %d: %d-%s-%02d%n", i,year,map.get(month),day);
}
}
}