#include<bits/stdc++.h>
using namespace std;
bool isr(int x){
if(x%4==0&&x%100!=0||x%400==0){
return true;
}else{
return false;
}
}
int main(){
ios::sync_with_stdio(0),cout.tie(0);
int y,m,d,h,k;
cin>>y>>m>>d>>h>>k;
if(h+k<24){
cout<<y<<m<<d<<h+k;
}else{
if(h+k>=24) h=(h+k)%24;d+=(h+k)/24;
if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){
if(d>=32) d=d%31; m+=d/31;
}else{
if(m==4||m==6||m==9||m==11){
if(d>=31) d=d%30; m+=d/30;
}else if(m==2){
if(isr(m)==true){
if(d>=30) d=d%29; m+=d/29;
}else{
if(d>=29) d=d%28; m+=d/28;
}
}
}
if(m>=13) m=m%12; y+=m/12;
}
cout<<y<<" "<<m<<" "<<d<<" "<<h;
return 0;
}