# No.296 n度寝 N, H, M, T = [int(i) for i in input().split()] print((H + ((M + T * (N - 1)) // 60)) % 24) print((M + T * (N - 1)) % 60)