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