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