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