#include<bits/stdc++.h>
using namespace std;
int y,m,d,h,k,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
cin>>y>>m>>d>>h>>k;
for(int i=1;i<=k;i++){
if(y%4==0&&y%100!=0) a[2]=29;
if(h==23){
h=0;
if(d==a[m]){
d=1;
if(m==12) m=1,y++;
else m++;
}else d++;
}else h++;
}cout<<y<<" "<<m<<" "<<d<<" "<<h;
return 0;
}