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