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