days ={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
y,m,d=map(int,raw_input().strip().split())
r=0
if (y%100==0 and y%400==0) or (y%4==0 and y%100<>0):
r=1
if r==1 and m==2:
mDays=days[m]+r+1
else:
mDays=days[m]+1
d=(d+1)%mDays
if d==0:
d=1
m=(m+1)%13
if m==0:
m=1
y=y+1
print y,m,d