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