N,H,M,T = map(int,input().split()) M += (N-1) * T H += M//60 H = H%24 M = M %60 print(f'{H}\n{M}')