N, H, M, T = map(int, raw_input().split()) M += (N-1) * T while M > 60: M -= 60 H += 1 H = H % 24 print H print M