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