inp = input().split() n,h,m,t = inp[0],inp[1],inp[2],inp[3] dm = (n-1)*t m+=dm h+=int(m/60) m%=60 h%=24 print(h) print(m)