1.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

public class Main {
public static void main(String[] args) throws Exception{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String inputLine;
while ((inputLine = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(inputLine);
int plus = new Integer(st.nextToken());
int day = new Integer(st.nextToken());
int month = new Integer(st.nextToken());
int year = new Integer(st.nextToken());
if(plus==0 && day==0 && month==0 && year==0) break;
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.println(day+" "+month+" "+year);
}
}
}