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