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