N, H, M, T = map(int, input().split()) sleep_time = (N-1)*T awake_h, awake_m = divmod(M + sleep_time, 60) awake_h = (awake_h + H)%24 print(awake_h, awake_m, sep='\n')