#include int main(void){ int n,h,m,mb,d; scanf("%d",&n); scanf("%d",&h); scanf("%d",&m); scanf("%d",&mb); d=(n-1)*mb; m=m+d; while(m>=60){ h++; m=m-60; } while(h>=24){ h=h-24; } if(m==0){ printf("%d\n0\n",h); } else{ printf("%d\n%d",h,m); } return 0; }