#include int main(){ int n,h,m,t; scanf("%d%d%d%d",&n,&h,&m,&t); t=h*60+m+(n-1)*t; printf("%d\n%d",(t/60)%24,t%60); return 0; }