N,H,M,T = [int(x) for x in input().split()] FG = H*60 + M LG = FG + T*(N-1) LH = (LG // 60) % 24 LM = LG % 60 print(LH) print(LM)