n,h,m,t=map(int,input().split()) p=t*(n-1) m+=p h+=1 if m>59 else 0 print(h%24) print(m%60)