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