N, H, M, T = (int(s) for s in input().split()) t0 = H*60 + M t = (t0 + (N-1)*T) % (24*60) print(t//60) print(t%60)