n,h,m,t = map(int, input().split()) d = (n-1)*t d2,mm=divmod(m + d,60) d3,hh=divmod(h+d2,24) print(hh) print(mm)