n,h,m,t=map(int,input().split()) deltatime=divmod((n-1)*t,60) timem=divmod(m+deltatime[1],60) timeh=divmod(h+deltatime[0]+timem[0],24) print(timeh[1]) print(timem[1])