N, H, M, T = [int(i) for i in input().split()] M += T * (N - 1) q, r = divmod(M, 60) M, H = r, H+q q, r = divmod(H, 24) H = r print(H, M, sep="\n")