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