N,H,M,T = map(int,input().split()) minitues = T*(N-1) M = M+minitues if M >= 60: H+=1 M-=60 print(H) print(M)