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