N, H, M, T = map(int, input().split()) min = H * 60 + M + T * (N - 1) h = min // 60 if h >= 24: h = h % 24 t = min % 60 print(h) print(t)