n,h,m,t=map(int,input().split()) m+=(n-1)*t q=int(m/60) m=m%60 h=h+q h=h%24 print(h) print(m)