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