#coding: utf-8 ##yuki_296 n,h,m,t=map(int,raw_input().split()) st=h*60+m et=(n-1)*t+st hour=(et/60)%24 mini=et%60 print hour print mini